MEGA65 / open-roms

A project to create unencumbered open-source ROMs for use on selected retro computers
Other
263 stars 18 forks source link

Nebulus does not run #20

Closed gardners closed 5 years ago

gardners commented 5 years ago

Nebulus sets $0314/$0315 to $EA31 and calls $FDA3:

.C:2c17  8D 11 D0    STA $D011
.C:2c1a  58          CLI
.C:2c1b  AD 01 DC    LDA $DC01
.C:2c1e  C9 EF       CMP #$EF
.C:2c20  D0 F9       BNE $2C1B
.C:2c22  78          SEI
.C:2c23  A9 31       LDA #$31
.C:2c25  8D 14 03    STA $0314
(C:$2c28) d
.C:2c28  A9 EA       LDA #$EA
.C:2c2a  8D 15 03    STA $0315
.C:2c2d  A9 F0       LDA #$F0
.C:2c2f  8D 1A D0    STA $D01A
.C:2c32  A9 00       LDA #$00
.C:2c34  8D 0D DC    STA $DC0D
.C:2c37  A9 0B       LDA #$0B
.C:2c39  8D 11 D0    STA $D011
.C:2c3c  20 A3 FD    JSR $FDA3
.C:2c3f  58          CLI

We therefore need to implement the callable part of the IRQ handler at $EA31, i.e., the part after the vector call. Vector insertion for IRQs should already be there.

$FDA3 is IOINIT "Initialise CIA I/O devices" according to p238 of Compute's Mapping the 64. We therefore need to make sure that this routine is at that location. I think at the moment IOINIT also initialises the VIC-II, which should be moved elsewhere, probably into CINIT?

gardners commented 5 years ago

Related to the above, Nebulus also JMPs to $EA7E in the end of its IRQ routine:

.C:2d7d  20 06 30    JSR $3006
.C:2d80  EE 19 D0    INC $D019
.C:2d83  4C 7E EA    JMP $EA7E
.C:2d86  A9 FF       LDA #$FF
.C:2d88  18          CLC
.C:2d89  69 03       ADC #$03

We know $EA81 is the do-nothing exit from IRQ, so $EA7E is 3 bytes earlier, and thus presumably calls some function within the IRQ handler, without doing everything. Quick google reveals:

https://csdb.dk/forums/index.php?roomid=11&topicid=5776

Basically $EA7E has an instruction that clears the CIA interrupt flag. Basically we need to read $DC0D to achieve this. We have the choice of LDA, LDX or LDY. It is really a free random choice, because the following instructions pop all registers off the stack.

gardners commented 5 years ago

Now gets to crack screen, and "PLAY HIGHSCORE OR TRAINER GAME [H/T]?" message, but doesn't proceed any further.

gardners commented 5 years ago

That code is a tight loop calling $FFE4 (get character of input) and checking for T/H. $FFE4 should already be implemented, but no input is read. This is almost certainly because IOINIT isn't at the correct location, and so no CIA interrupts are triggered, and thus the keyboard is not scanned.

gardners commented 5 years ago

All fixed. Nebulus now works (tested by playing level one and first fish intermission through).