JohnEarnest / Octo

A Chip8 IDE
MIT License
682 stars 55 forks source link

check scroll up opcode #68

Closed whoozle closed 7 years ago

whoozle commented 7 years ago

Many manuals I could find on the internet mention that scroll up instruction has 00 BN form, but it looks that octo uses 00 DN form. Which is right opcode?

JohnEarnest commented 7 years ago

SCHIP only had scroll-left, scroll-right, and scroll-down instructions. The scroll-up instruction provided in Octo is an XO-Chip extension provided for the sake of symmetry.

If anyone else is documenting 0x00BN as a scroll instruction I'd guess it is their own custom extension?

whoozle commented 7 years ago

I don't know , It looks like it's the most complete set of manuals: https://twitter.com/videocats/status/921065189931397122 It appears to be in every chip 8 opcode manual I googled. Sorry, I'm on the phone now, can't provide you with links I got before

whoozle commented 7 years ago

LOL !!! sorry for cat link :)

It has been mentioned in some emulators https://massung.github.io/CHIP-8/ https://github.com/trapexit/chipce8/blob/master/CHIP-8.md Probably they copy-paste single wrong manual or some documented emu quirk.

This is massive old manuals collection: https://github.com/trapexit/chip-8_documentation

Worth checking if it's widely used already

trapexit commented 7 years ago

It's been a while since I put together that doc with all the opcodes from different versions. I don't recall where I got the scroll up one from.

Chromatophore commented 7 years ago

Hello!

So, I have investigated this issue to see if 00BN worked with the 199X era SCHIP 1.1 binary on an HP-48. I'm afraid to say that my result was a fairly conclusive 'no'. I have no reason to suspect there were later binaries created at current.

I first created a test program in octo: http://johnearnest.github.io/Octo/index.html?gist=b0006a3aadb4cf43a0fb63aeb90fdece and simply ran this on the calculator, and it crashed out with result 538d, which I believe indicates that the PC hit the location of the mystery 00BN instruction and the program terminated.

Following this, I actually tore apart the SCHIP 1.1 Binary via disassembly to locate the instruction handlers for these operations, which I can show you in... kind of simple form here:

# Despatch handler excerpt
006E4   GOTO    00448

# Despatch handler for 0??? commands:
00448   GOSUB   00333       # Call 'NNNC' sub, puts ?NNN -> C register
0044C   A=C A       # Copies C into A:
0044E   C=0 A
# Now we test for a variety of commands:
00450   LC  E0      # 00E0 command - erase screen
00454   ?A#C    A
00457   GOYES   00498       # if A != C, branch
...
00498   LC  EE      # 00EE command : subroutine return
0049C   ?A#C    A
0049F   GOYES   004D7       # if A != C, branch
...
004D7   LC  FF      # Load FF to test for 00FF : Enable Extended instruction
004DB   ?A#C    A       # Does this not match our instruction? (Tests 00FF)
004DE   GOYES   004FB       # if A != C, branch
...
004FB   C=C-1   B       # Seems to be detecting 00FE : Disable Extended via decrement
004FE   ?A#C    A
00501   GOYES   0051D       # if A != C, branch
...
0051D   C=C-1   B       # 00FD : Exit interpreter
00520   ?A#C    A
00523   GOYES   00529       # if A != C, branch
...
00529   C=C-1   B       # 00FC : scroll left
0052C   ?A#C    A
0052F   GOYES   00579       # if A != C, branch
...
00579   C=C-1   B       # 00FB : scroll right
0057C   ?A#C    A
0057F   GOYES   005CC       # if A != C, branch
...
005CC   C=A A       # A contains the original command, restore this into C
005CE   CSR A       # Shift nibble right
005D0   C=C-12  P       # Subtract 12
005D6   ?C=0    P       # Test vs 0
005D9   GOYES   005DF       # If result is 0, ie, original command was 00C? : Scroll Down
005DB   GOTO    0066B       # Thus if original command was not 00C?, goto 66B
... 
0066B   RTNSC           # RTNSC is return set carry.
# If carry is set on return, conclude unhandled command and terminate.

You can follow each GOYES/GOTO to the following block of code. The prospective CHIP-8 instruction is tested for being either the 00E0 or EE command, then FF down through to FB. Finally, 00C? is tested, and then if the command was not any of those, the program terminates out. Our hopeful 00B? command has no code to handle it and, therefore, with it additionally not being included in the SCHIP 1.1 release notes, and so far as I'm aware, not included in any period roms, I think it is fairly safe to conclude that the command was not implemented on the HP48's super chip platform.

I'm honestly not really sure why it wasn't though. The result though appears that there is not a 'correct' op code.

JohnEarnest commented 7 years ago

OK, I think for our purposes this is settled. @trapexit, could you update your docs? I've reached out to the author of the interpreter @whoozle pointed out.

trapexit commented 7 years ago

Will do. Thanks.

whoozle commented 7 years ago

So the conclusion is: no evidence that scroll-up was even implemented on any chip8 emulator/VIP, so we consider XO's Dx form is right for the time being.

Thanks a lot!

metteo commented 4 years ago

My 2 cents: David Winter the creator of many games for Chip8 had his own website and emulator. The emulator's bootloader called boot-128 uses 2 custom instructions: 0x0000 & 0x0001. The 0x0000 instruction does what 0x00D6 would do: scroll the screen 6 rows up.

ludwhe commented 4 years ago

My own two cents: the first mention I found of 00BN being used to scroll up was in Martijn Wenting's MEGA-CHIP8, which is an extension of Super Chip-48.