From 5ba7a73f3adb78b205b28ec44ba42bb29ead0680 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 18 Oct 2018 19:46:35 -0500 Subject: [PATCH] New IIgs paddle code and bug fixes. --- src/jIIgs.asm | 106 ++++++++++++++++++++++++++++++++------------------ src/jIIgs.c | 26 ++++++++++++- src/test.c | 6 ++- 3 files changed, 97 insertions(+), 41 deletions(-) diff --git a/src/jIIgs.asm b/src/jIIgs.asm index 7986b0a..4629804 100644 --- a/src/jIIgs.asm +++ b/src/jIIgs.asm @@ -224,10 +224,10 @@ t equ 1 asmBorder start jsubroutine (2:c) short m - lda $E0C034 + lda >$E0C034 and #$F0 ora c - sta $E0C034 + sta >$E0C034 long m jreturn end @@ -288,9 +288,9 @@ asmGetVbl start asmGrOff start jsubroutine short m - lda $E1C029 + lda >$E1C029 and #$7F - sta $E1C029 + sta >$E1C029 long m jreturn end @@ -301,45 +301,77 @@ asmGrOff start asmGrOn start jsubroutine short m - lda $E1C029 + lda >$E1C029 ora #$C1 - sta $E1C029 + sta >$E1C029 long m jreturn end ;---------------------------------------- ; Reads controller axis +; Thank you to John Brooks for this code! ;---------------------------------------- asmJoy start -count equ 1 +pret0 equ 1 +pret1 equ 2 -strobe equ $00C070 ; Paddle timer reset -paddle equ $00C064 ; First paddle address +speed equ $00C036 +pdl0 equ $00C064 +pdl1 equ $00C065 +ptrig equ $00C070 - jsubroutine (2:which),2 + jsubroutine ,2 - lda which ; Which paddle/axis do we want? - tax - php - sei ; Disable interrupts - stz count ; Reset paddle value counter - short m - lda >strobe ; Start timer -pdlLbl1 nop ; Delay some - nop - nop - nop - inc count ; Increment paddle value counter - beq pdlLbl2 ; If we loop back to zero, Z is set and we branch - lda >paddle,x ; Check paddle value - bmi pdlLbl1 ; High bit not set yet -pdlLbl2 dec count ; Decrement one. Makes timeouts equal 255. - long m - plp ; Restore interrupt setting + php ; Save mx reg size bits + phb ; Save data bank + short m,i ; 8-bit m,x + sei ; disable interrupts - jreturn 2:count + ldx #0 ; Zero paddle 0 counter + phx + plb ; Set DBR = 0 + + ldy speed ; Read current system speed + phy ; Save it + lda #$80 ; Fast/Slow bit + trb speed ; Force 1 Mhz + + txy ; Zero paddle 1 counter + + pha ; Dummy data for wait pla + lda ptrig ; Start paddle timers. Wait 11 cycles then read pdl0 + pla ; 4c + +gotpdl1 xba ; 3c +chkpdl0 lda pdl0 ; 4c. Read pdl0. 10c until pdl1 read + bpl gotpdl0 ; 2/3c taken if pdl0 is done + inx ; 2c + inx ; 2c + lda pdl1 ; 4c. Read pdl1. 12c until pdl0 read + bmi nogots ; 2/3c + bpl gotpdl1 ; 3c always taken +nogots iny ; 2c + jmp chkpdl0 ; 3c +gotpdl0 xba ; 3c + lda pdl1 ; 4c. Read pdl1. 12c until pdl0 read + bmi nogots ; 3c if pdl1 not done + + pla ; Reload original speed + sta speed ; Restore it + + plb ; Restore Data Bank + + stx pret0 ; Store result + tya + asl a ; Scale 0-127 pdl1 to 0-254 + sta pret1 + + plp ; Restore mx 8/16 mode and interrupt enable state + long m,i + + jreturn 2:pret0 end ;---------------------------------------- @@ -380,10 +412,10 @@ PBoth sta temp3 ; Store accumulator in temp3 adc temp1 ; Add X position to address with carry tax ; Transfer accumulator to x - lda SHRShad,x ; Load existing pixels into accumulator + lda >SHRShad,x ; Load existing pixels into accumulator and temp2 ; AND accumulator with temp2 ora temp3 ; OR accumulator with temp3 - sta SHRShad,x ; Store updated pixels back into memory + sta >SHRShad,x ; Store updated pixels back into memory jreturn end @@ -400,9 +432,9 @@ asmSlam start jsubroutine short m ; Turn Shadowing On - lda $E0C035 + lda >$E0C035 and #$F7 - sta $E0C035 + sta >$E0C035 long m php ; Push Processor Status Register @@ -581,12 +613,10 @@ peiInts lda #0 ; Swap main 48k into bank 0 sta >$E0C068-1 lda >StackPtr ; Load original Stack Pointer into Accumulator tcs ; Transfer Accumulator to Stack Pointer (Restores original stack) - pld ; Restore direct page cli ; Go Interrupts! Go! sei ; Stop interrupts - phd lda #$3000 ; Read/write aux 48k (SHR) via bank 0 sta >$E0C068-1 @@ -602,9 +632,9 @@ peiEnd lda #0 ; Swap main 48k into bank 0 plp ; Restore processor register short m ; Turn Shadowing Off - lda $E0C035 + lda >$E0C035 ora #$08 - sta $E0C035 + sta >$E0C035 long m jreturn @@ -627,7 +657,7 @@ asmStart start ldx #0 ; Load 0 into x register lda #0 ; Load 0 into accumulator clc ; Clear carry flag -STL sta ScanTable,x ; Store accumulator in ScanTable+x +STL sta >ScanTable,x ; Store accumulator in ScanTable+x adc #160 ; Add 160 to accumulator inx ; Increment x inx ; Increment x diff --git a/src/jIIgs.c b/src/jIIgs.c index cf76ee6..670ea5e 100644 --- a/src/jIIgs.c +++ b/src/jIIgs.c @@ -48,7 +48,8 @@ typedef struct { extern void asmBorder(int c); extern void asmGrOff(void); extern void asmGrOn(void); -extern int asmJoy(int which); +//extern int asmJoy(int which); +extern int asmJoy(void); extern void asmSlam(void); extern void asmStart(int myID, int hertzBy10); extern void asmStop(void); @@ -114,7 +115,28 @@ void jlDrawClear(void) { int jlGameGetAxis(byte which) { - return asmJoy((int)which) - 128; + static bool xRead = true; + static bool yRead = true; + static int paddles = 0; + int r; + + if (which == 0) { + if (xRead) { + paddles = asmJoy(); + xRead = true; + yRead = false; + } + r = paddles & 0x00ff; + } else { + if (yRead) { + paddles = asmJoy(); + xRead = false; + yRead = true; + } + r = (paddles & 0xff00) >> 8; + } + + return r - 128; } diff --git a/src/test.c b/src/test.c index fab60ab..c565e00 100644 --- a/src/test.c +++ b/src/test.c @@ -58,6 +58,7 @@ int main(void) { jlStaT *kanga = NULL; jlStaT *font = NULL; + int y; jlUtilStartup("JoeyLib Test"); @@ -72,7 +73,10 @@ int main(void) { jlPaletteSet(15, 15, 15, 15); while (!jlKeyPressed()) { - printAt(font, 1, 20, "T = %d ", jlUtilTimer()); + y = 17; + printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0)); + printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1)); + printAt(font, 1, y++, "T = %d ", jlUtilTimer()); jlDisplayPresent(); } jlKeyRead();