Skip to content

Commit

Permalink
Optimized Z80 communication. Fixed save states.
Browse files Browse the repository at this point in the history
  • Loading branch information
FluBBaOfWard committed Oct 19, 2022
1 parent 6dec3fe commit 7d5dc21
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 90 deletions.
4 changes: 4 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ NGPDS revision history
-=-=-=-=-=-=-=-=-=-=-=-


V0.5.4 - 2022-10-19 (FluBBa)
Optimized Z80 communication.
Fixed savestates.

V0.5.3 - 2022-10-18 (FluBBa)
Fixed savestates.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NGPDS V0.5.3
# NGPDS V0.5.4

<img align="right" width="220" src="./logo.png" />

Expand Down
1 change: 1 addition & 0 deletions source/Cart.s
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ROM_Space:
// .incbin "ngproms/Evolution - Eternal Dungeons (E).ngc"
// .incbin "ngproms/Fantastic Night Dreams Cotton (E).ngc"
// .incbin "ngproms/Fatal Fury F-Contact (JUE) (M2).ngc"
// .incbin "ngproms/King of Fighters R-2 (JUE) (M2).ngc"
// .incbin "ngproms/Last Blade, The - Beyond the Destiny (E).ngc"
// .incbin "ngproms/Metal Slug - 1st Mission (JUE) (M2).ngc"
// .incbin "ngproms/SNK Gals' Fighters (UE).ngc"
Expand Down
2 changes: 1 addition & 1 deletion source/Gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "K2GE/Version.h"
#include "K2Audio/Version.h"

#define EMUVERSION "V0.5.3 2022-10-18"
#define EMUVERSION "V0.5.4 2022-10-19"

#define ALLOW_SPEED_HACKS (1<<17)

Expand Down
32 changes: 8 additions & 24 deletions source/Memory.s
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
.global tlcs_romH_R
.global z80RamW
.global z80SoundW
.global z80LatchW
.global z80IrqW
.global z80RamR
.global z80LatchR


.syntax unified
Expand Down Expand Up @@ -394,6 +392,14 @@ z80RamW: ;@ Write mem (0x0000-0x0FFF)
bxmi lr
b empty_W
;@----------------------------------------------------------------------------
z80RamR: ;@ Read Ram (0x0000-0x0FFF)
;@----------------------------------------------------------------------------
cmp addy,#0x1000
ldrmi r1,=ngpRAM+0x3000
ldrbmi r0,[r1,addy]
bxmi lr
b empty_R
;@----------------------------------------------------------------------------
z80SoundW: ;@ Write mem (0x4000-0x4001)
;@----------------------------------------------------------------------------
mov r1,#0x4000
Expand All @@ -404,14 +410,6 @@ z80SoundW: ;@ Write mem (0x4000-0x4001)
beq T6W28_L_W
b empty_W
;@----------------------------------------------------------------------------
z80LatchW: ;@ Write mem (0x8000)
;@----------------------------------------------------------------------------
cmp addy,#0x8000
ldreq r1,=commByte
strbeq r0,[r1]
bxeq lr
b empty_W
;@----------------------------------------------------------------------------
z80IrqW: ;@ Write mem (0xC000)
;@----------------------------------------------------------------------------
cmp addy,#0xC000
Expand All @@ -421,20 +419,6 @@ z80IrqW: ;@ Write mem (0xC000)
bl setInterruptExternal
ldmfd sp!,{r3,lr}
bx lr
;@----------------------------------------------------------------------------
z80RamR: ;@ Read Ram (0x0000-0x0FFF)
;@----------------------------------------------------------------------------
cmp addy,#0x1000
ldrmi r1,=ngpRAM+0x3000
ldrbmi r0,[r1,addy]
bxmi lr
b empty_R
;@----------------------------------------------------------------------------
z80LatchR: ;@ Read communication latch (0x8000)
;@----------------------------------------------------------------------------
cmp addy,#0x8000
beq z80ReadLatch
b empty_R

;@----------------------------------------------------------------------------
.end
Expand Down
122 changes: 58 additions & 64 deletions source/io.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef __arm__

#include "TLCS900H/TLCS900H.i"
#include "ARMZ80/ARMZ80.i"
#include "K2GE/K2GE.i"

.global ioReset
Expand All @@ -18,10 +19,10 @@
.global t9LoadB_Low
.global t9StoreB_Low
.global updateSlowIO
.global z80ReadLatch
.global z80LatchR
.global z80LatchW
.global gSubBatteryLevel
.global batteryLevel
.global commByte
.global system_comms_read
.global system_comms_poll
.global system_comms_write
Expand Down Expand Up @@ -49,7 +50,7 @@ ioReset:
;@----------------------------------------------------------------------------
initSysMem: ;@ In r0=values ptr.
;@----------------------------------------------------------------------------
stmfd sp!,{r4-r5,lr}
stmfd sp!,{r4-r5,t9optbl,lr}

mov r4,r0
mov r5,#0xFF
Expand All @@ -60,40 +61,33 @@ initMemLoop:
subs r5,r5,#1
bpl initMemLoop

ldmfd sp!,{r4-r5,pc}
ldmfd sp!,{r4-r5,t9optbl,pc}
;@----------------------------------------------------------------------------
ioSaveState: ;@ In r0=destination. Out r0=size.
.type ioSaveState STT_FUNC
;@----------------------------------------------------------------------------
stmfd sp!,{lr}

ldr r1,ioExtraState
str r1,[r0],#4
mov r2,#0x100
stmfd sp!,{r2,lr}

ldr r1,=systemMemory
mov r2,#0x100
bl memcpy

ldmfd sp!,{lr}
ldr r0,=0x104
ldmfd sp!,{r0,lr}
bx lr
;@----------------------------------------------------------------------------
ioLoadState: ;@ In r0=source. Out r0=size.
.type ioLoadState STT_FUNC
;@----------------------------------------------------------------------------
stmfd sp!,{lr}

ldr r1,[r0],#4
str r1,ioExtraState

bl initSysMem

ldmfd sp!,{lr}
;@----------------------------------------------------------------------------
ioGetStateSize: ;@ Out r0=state size.
.type ioGetStateSize STT_FUNC
;@----------------------------------------------------------------------------
ldr r0,=0x104
mov r0,#0x100
bx lr
;@----------------------------------------------------------------------------
transferTime:
Expand Down Expand Up @@ -176,13 +170,22 @@ EMUinput: ;@ This label here for main.c to use
.long 0 ;@ EMUjoypad (this is what Emu sees)

;@----------------------------------------------------------------------------
z80ReadLatch:
z80LatchW: ;@ Write communication latch (0x8000)
;@----------------------------------------------------------------------------
cmp addy,#0x8000
strbeq r0,systemMemory+0xBC ;@ Z80 communication byte
bxeq lr
b empty_W
;@----------------------------------------------------------------------------
z80LatchR: ;@ Read communication latch (0x8000)
;@----------------------------------------------------------------------------
cmp addy,#0x8000
bne empty_R
stmfd sp!,{lr}
mov r0,#0
bl Z80SetNMIPin
ldmfd sp!,{lr}
ldrb r0,commByte ;@ 0xBC
ldrb r0,systemMemory+0xBC ;@ Z80 communication byte
bx lr

;@----------------------------------------------------------------------------
Expand Down Expand Up @@ -298,7 +301,7 @@ checkForAlarm:
t9StoreB_Low:
;@----------------------------------------------------------------------------
ldr t9optbl,=tlcs900HState ;@ !!!This should not be needed when called from asm.
ldr r2,=systemMemory
adr r2,systemMemory
strb r0,[r2,r1]

cmp r1,#0x50 ;@ Serial channel 0 buffer.
Expand All @@ -319,10 +322,6 @@ t9StoreB_Low:
cmp r1,#0xBA ;@ Z80 NMI
beq Z80_nmi_do

cmp r1,#0xBC ;@ Z80_COM
strbeq r0,commByte
bxeq lr

cmp r1,#0xA0 ;@ T6W28, Right
beq T6W28_R_W
cmp r1,#0xA1 ;@ T6W28, Left
Expand Down Expand Up @@ -395,19 +394,52 @@ t9LoadB_Low:
ldrbeq r0,sc0Buf
bxeq lr

cmp r0,#0xBC ;@ Z80_COM
ldrbeq r0,commByte
bxeq lr

ldr r2,=systemMemory
ldrb r0,[r2,r0]
bx lr

;@----------------------------------------------------------------------------
watchDogW:
;@----------------------------------------------------------------------------
bx lr
;@----------------------------------------------------------------------------
Z80In:
;@----------------------------------------------------------------------------
mov r11,r11 ;@ No$GBA breakpoint
mov r0,#0
bx lr
;@----------------------------------------------------------------------------
Z80Out:
;@----------------------------------------------------------------------------
;@ mov r11,r11 ;@ No$GBA breakpoint
mov r0,#0
b Z80SetIRQPin
;@----------------------------------------------------------------------------
gSubBatteryLevel:
.long 0x3000000 ;@ subBatteryLevel
batteryLevel:
.long 0xFFFF ;@ Max = 0xFFFF (0x3FF)
;@ To start > 0x8400 (0x210)
;@ Low < 0x8000 (0x200)
;@ Bad < 0x7880 (0x1E2)
;@ Shutdown <= 0x74C0 (0x1D3)
;@ Alarm minimum = 0x5B80 (0x16E)
;@----------------------------------------------------------------------------
systemMemory:
.space 0x100

ioExtraState:
rtcTimer:
.byte 0
sc0Buf:
.byte 0
commStatus:
.byte 0
.space 1

;@----------------------------------------------------------------------------
.section .text
;@----------------------------------------------------------------------------
SysMemDefault:
;@ 0x00 ;@ 0x08
.byte 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x08, 0xFF, 0xFF
Expand Down Expand Up @@ -441,44 +473,6 @@ SysMemDefault:
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
;@ 0xF0 ;@ 0xF8
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00


;@----------------------------------------------------------------------------
watchDogW:
;@----------------------------------------------------------------------------
bx lr
;@----------------------------------------------------------------------------
Z80In:
;@----------------------------------------------------------------------------
mov r11,r11 ;@ No$GBA breakpoint
mov r0,#0
bx lr
;@----------------------------------------------------------------------------
Z80Out:
;@----------------------------------------------------------------------------
;@ mov r11,r11 ;@ No$GBA breakpoint
mov r0,#0
b Z80SetIRQPin
;@----------------------------------------------------------------------------
gSubBatteryLevel:
.long 0x3000000 ;@ subBatteryLevel
batteryLevel:
.long 0xFFFF ;@ Max = 0xFFFF (0x3FF)
;@ To start > 0x8400 (0x210)
;@ Low < 0x8000 (0x200)
;@ Bad < 0x7880 (0x1E2)
;@ Shutdown <= 0x74C0 (0x1D3)
;@ Alarm minimum = 0x5B80 (0x16E)
ioExtraState:
rtcTimer:
.byte 0
sc0Buf:
.byte 0
commStatus:
.byte 0
commByte:
.byte 0
// .space 2

.end
#endif // #ifdef __arm__

0 comments on commit 7d5dc21

Please sign in to comment.