Rockbox Technical Forums

Support and General Use => Plugins/Viewers => Topic started by: bbail on January 23, 2021, 03:50:32 AM

Title: chip8 viewer Rockbox compatible 15puzzle
Post by: bbail on January 23, 2021, 03:50:32 AM
I did a rewrite of the 15 chip8 game to adapt it to my Rockbox'd e200.
I used Werner Stoop's chip8 emulator and assembler to develop the code.
It worked fine in the emulator. When I ran it in the Rockbox simulator the program stopped accepting new key inputs once 2 or 8 were pressed. I could press 4 and 6 keys forever, but once 2 or 8 were pressed, no more input.
Same thing on the actual e200.
The program is still running (there is a timer that continues incrementing), but it no longer accepts key inputs.
I wrote a simple keypress program as a test. It does the same thing.
   
                LD V5,12
loop:       LD V0,K               ;get key
                LD F,V0
                DRW V5,V5,5     ;output
 
                LD V7, 1               ;wait value
                LD DT, V7
wait:        LD V7, DT
                SE V7, 0
                JP wait

                LD  F, V0
                DRW V5,V5,5       ;clear
                JP loop

Unfortunately, this leaves only 3 functioning keys for any programs using the Chip8 viewer on a Sansa e200
Title: Re: chip8 viewer keys 2 and 8
Post by: bbail on January 24, 2021, 06:45:57 PM
I looked through chip8.c and saw that it handles all of the keys the same.
I suspect that because 2 and 8 are mapped to the scroll wheel, that they are handled differently in Rockbox.
The scroll wheel must have a quadrature input in order to distinguish CW and CCW.
In chip8, there are tables of key defines:

#elif CONFIG_KEYPAD == SANSA_E200_PAD || \
      CONFIG_KEYPAD == SANSA_FUZE_PAD
#define CHIP8_OFF  BUTTON_POWER
#define CHIP8_KEY2 BUTTON_SCROLL_BACK
#define CHIP8_KEY4 BUTTON_LEFT
#define CHIP8_KEY5 BUTTON_SELECT
#define CHIP8_KEY6 BUTTON_RIGHT
#define CHIP8_KEY8 BUTTON_SCROLL_FWD

It seems to me this table could be changed to:

#define CHIP8_OFF  BUTTON_POWER
#define CHIP8_KEY2 BUTTON_UP
#define CHIP8_KEY4 BUTTON_LEFT
#define CHIP8_KEY5 BUTTON_SELECT
#define CHIP8_KEY6 BUTTON_RIGHT
#define CHIP8_KEY8 BUTTON_DOWN

BUTTON_UP and BUTTON_DOWN are defined for the e200, so this would map out the troublesome scroll wheel buttons.
The up and down buttons appear to be non-functioning while chip8 is running, so I don't see a conflict.

I'm adding the .ch8 files for the source from the previous post, so anyone can see for them selves without tracking down an assembler.
And the .c8k files show the 24568 keys translated to ABCDE. No need to use these except to see keys translated.
keypress1 has 1 loaded in the delay timer, keypress40 has 40 loaded in the delay timer.
They are binary and text anyway. Just correct the file extensions back to .ch8 and .c8k



Update:
I downloaded the source and tools and was able to compile a e200v2 simulator. (The windows version on the web site had a bug and kept shutting down.) I made these small changes and re-compiled a simulator. The changes do indeed correct the problem.
Title: Re: chip8 viewer keys 2 and 8
Post by: bbail on January 30, 2021, 12:32:50 AM
Update:
Here is my version of the 15Puzzle or Puzzle  chicklet puzzle.
It is not complete, but it functions on Rockbox with the caveat that Sansa e200's and Fuze's require the changes in chip8.c to address buttons 2 and 8. It uses buttons 2 4 6 8 to manipulate the chicklets.
15Puzzle required 16 buttons and Puzzle seems to have a switch bounce problem.
I added switch debounce to mine, but the buttons are a little sluggish. I'll look at that.
This one includes a move counter and an elapse timer. The timer stops at completion of the puzzle.
I'm working on some setup and end things before I call it done. I called it RockChip15 after Rockbox CHIP8 Fifteen puzzle. Maybe that's a mistake. I see there is a company called Rockchip.
Rename to .ch8 file extents.
Title: Re: chip8 viewer Rockbox compatible 15puzzle
Post by: bbail on February 03, 2021, 12:38:51 AM
Here is RockChip15v1_0.ch8.
I improved the key response some and added setup controls so that the timer and counter can be reset and the puzzle can be started with some predefined arrangements. I also found and corrected an error in the randomize board routine.
I can't think of much else to do with it, so I'm calling it done.

I had an ELF computer board years ago that used the RCA 1802 microprocessor. It came as a kit. It had 256 bytes of memory, a hex key pad and a 2 or 4 7 segment led display. I designed and built a 4k byte memory board for it. I sold it all at an electronic flea market a long time ago. I hadn't thought about it much until I looked into the chip8 emulator on Rockbox and realized that they were related.

I should push the needed chip8.c changes needed for the e200 up through gerrit, but it looks like too big of a hill for me to climb right now. They are very small and I was able to download the source and tools and compile the changes using the instructions on the relevent wiki pages. Unfortunately the latest dev files caused the usb port to be locked out. It's not much of a problem though, since normally I just use the sd card to transfer files anyway. Hopefully, I can git the 3.15 source files and try again.
Learning C has been on my todo list for decades. This is at least a start. I wonder if my original K&R C book is still relevent.
Title: Re: chip8 viewer Rockbox compatible 15puzzle
Post by: bbail on February 20, 2021, 07:20:34 PM
I thought  I was done with this. You just don't know what you don't know.
I acquired a book entitled "The Puzzle Universe, A History of Mathematics in 315 Puzzles" by Ivan Moscovich. A short article in the book on the 15 puzzle informed me that it originated in the 1870's and that the set of possible initial conditions is only half of what I had thought. It showed no proof, but a quick search on the internet took care of that. The set of 16! initial conditions consists of  two non-intersecting subsets, ie. the EF set and the FE set.
In the program, I had allowed for any of the 16! positions to start and I don't know of an easy way of tell in which subset the starting position may be, so I modified the test for puzzle completion to include both EF and FE.
I also changed the predefined starting positions to all be members of the EF subset.