guard against C0EC crossing a page

This commit is contained in:
Peter Ferrie 2021-06-07 14:42:03 -07:00
parent e4f6ed2a26
commit fc74b8b31a
3 changed files with 100 additions and 0 deletions

View File

@ -417,18 +417,32 @@ VerifyInfocom18
lda #$00 lda #$00
-- ldy #$56 -- ldy #$56
.x1
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x1 != >* {
!serious "branch crosses a page"
}
eor $BA00,x ; from universal RWTS eor $BA00,x ; from universal RWTS
dey dey
bne - bne -
.x2
!warn "x1=",*
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!warn "x2=",*
!if >.x2 != >* {
!serious "branch crosses a page"
}
eor $BA00,x ; from universal RWTS eor $BA00,x ; from universal RWTS
iny iny
bne - bne -
.x3
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x3 != >* {
!serious "branch crosses a page"
}
eor $BA00,x ; from universal RWTS eor $BA00,x ; from universal RWTS
bne .badsect bne .badsect
dec tmp dec tmp
@ -495,15 +509,23 @@ VerifyInfocom18
+ ldy #4 + ldy #4
- dey - dey
beq .badrw18 beq .badrw18
.x4
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x4 != >* {
!serious "branch crosses a page"
}
lda $BA00,x lda $BA00,x
eor #$A5 eor #$A5
bne - bne -
sta $3A sta $3A
tay tay
.x5
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x5 != >* {
!serious "branch crosses a page"
}
eor $3A eor $3A
eor $BA00,x eor $BA00,x
sta $2F sta $2F
@ -511,32 +533,48 @@ VerifyInfocom18
asl asl
asl asl
sta $30 sta $30
.x6
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x6 != >* {
!serious "branch crosses a page"
}
and #$C0 and #$C0
ora $BA00,x ora $BA00,x
sta $3A sta $3A
lda $30 lda $30
asl asl
asl asl
.x7
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x7 != >* {
!serious "branch crosses a page"
}
sta $30 sta $30
and #$C0 and #$C0
ora $BA00,x ora $BA00,x
sta $3B sta $3B
lda $30 lda $30
asl asl
.x8
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x8 != >* {
!serious "branch crosses a page"
}
asl asl
ora $BA00,x ora $BA00,x
eor $3B eor $3B
eor $2F eor $2F
iny iny
bne -- bne --
.x9
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x9 != >* {
!serious "branch crosses a page"
}
eor $BA00,x eor $BA00,x
eor $3A eor $3A
and #$3F and #$3F
@ -555,22 +593,38 @@ VerifyInfocom18
jmp .badsect jmp .badsect
.rw18pro .rw18pro
.x10
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x10 != >* {
!serious "branch crosses a page"
}
lda $BA00,x ; region (half) lda $BA00,x ; region (half)
sta $2C sta $2C
.x11
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x11 != >* {
!serious "branch crosses a page"
}
lda $BA00,x ; region (half) lda $BA00,x ; region (half)
sta $2D sta $2D
.x12
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x12 != >* {
!serious "branch crosses a page"
}
lda $BA00,x ; checksum lda $BA00,x ; checksum
eor $2C eor $2C
eor $2D eor $2D
bne + bne +
.x13
-- ldx $C0EC -- ldx $C0EC
bpl -- bpl --
!if >.x13 != >* {
!serious "branch crosses a page"
}
lda $BA00,x ; epilogue lda $BA00,x ; epilogue
eor #$AA eor #$AA
+ rts + rts
@ -604,12 +658,20 @@ read13
cmp #$B5 cmp #$B5
bne + bne +
ldy #$03 ldy #$03
.x14
-- lda $C0EC -- lda $C0EC
bpl -- bpl --
!if >.x14 != >* {
!serious "branch crosses a page"
}
rol rol
sta $3C sta $3C
.x15
- lda $C0EC - lda $C0EC
bpl - bpl -
!if >.x15 != >* {
!serious "branch crosses a page"
}
and $3C and $3C
dey dey
bne -- bne --
@ -622,18 +684,30 @@ read13
eor #$AD eor #$AD
bne .readaddr bne .readaddr
-- ldy #$9A -- ldy #$9A
.x16
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x16 != >* {
!serious "branch crosses a page"
}
eor $800,x eor $800,x
dey dey
bne - bne -
.x17
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x17 != >* {
!serious "branch crosses a page"
}
eor $800,x eor $800,x
iny iny
bne - bne -
.x18
- ldx $C0EC - ldx $C0EC
bpl - bpl -
!if >.x18 != >* {
!serious "branch crosses a page"
}
eor $800,x eor $800,x
cmp #$01 ; set carry if non-zero cmp #$01 ; set carry if non-zero
!byte $2c !byte $2c

View File

@ -247,8 +247,12 @@ ReadChoplifter
.prolog3 .prolog3
cmp #$D1 ; SMC cmp #$D1 ; SMC
bne - ; this had the same bug bne - ; this had the same bug
.x1
-- lda $C0EC ; timing issue requires unrolling part of this -- lda $C0EC ; timing issue requires unrolling part of this
bpl -- bpl --
!if >.x1 != >* {
!serious "branch crosses a page"
}
sec sec
rol rol
sta tmp sta tmp
@ -263,8 +267,12 @@ ReadChoplifter
sec sec
rol rol
sta tmp sta tmp
.x2
- lda $C0EC - lda $C0EC
bpl - bpl -
!if >.x2 != >* {
!serious "branch crosses a page"
}
and tmp and tmp
sta (BASEPAGE+8)<<8,y sta (BASEPAGE+8)<<8,y
iny iny

View File

@ -158,6 +158,9 @@ JustTheSameDamnThingOverAndOver
sta @cmp+1 ; 4 sta @cmp+1 ; 4
@loop lda $C0EC ; 4 @loop lda $C0EC ; 4
bpl @loop ; 2 when not taken bpl @loop ; 2 when not taken
!if >@loop != >* {
!serious "branch crosses a page"
}
dex ; 2 dex ; 2
bne @cmp ; 2 when not taken bne @cmp ; 2 when not taken
dec unform+1 ; 5 dec unform+1 ; 5
@ -201,6 +204,9 @@ IsUnformatted
@reset ldy #$00 @reset ldy #$00
@loop ldx $C0EC ; 4 @loop ldx $C0EC ; 4
bpl @loop ; 2 when not taken bpl @loop ; 2 when not taken
!if >@loop != >* {
!serious "branch crosses a page"
}
dec unform ; 5 dec unform ; 5
bne + ; 2 when not taken bne + ; 2 when not taken
dec unform+1 ; 5 dec unform+1 ; 5
@ -246,8 +252,12 @@ IsEATrack6
; out: A contains nibble value ; out: A contains nibble value
;------------------------------- ;-------------------------------
ReadNib ReadNib
.x1
- lda $C0EC - lda $C0EC
bpl - bpl -
!if >.x1 != >* {
!serious "branch crosses a page"
}
rts rts
;------------------------------- ;-------------------------------
@ -259,12 +269,20 @@ ReadNib
; @tmp clobbered ; @tmp clobbered
;------------------------------- ;-------------------------------
Read4x4 Read4x4
.x2
- lda $C0EC - lda $C0EC
bpl - bpl -
!if >.x2 != >* {
!serious "branch crosses a page"
}
sec sec
rol rol
sta tmp sta tmp
.x3
- lda $C0EC - lda $C0EC
bpl - bpl -
!if >.x3 != >* {
!serious "branch crosses a page"
}
and tmp and tmp
rts rts