Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some how-could-this-ever-have-worked issues with BBC BASIC. #21

Merged
merged 4 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions third_party/bbcbasic/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ for _, f in pairs(srcs) do
end

ld80 {
name = "bbcbasic_img",
name = "bbcbasic",
address = 0x100,
srcs = {
"+patch",
"-P0200",
Expand All @@ -26,7 +27,3 @@ ld80 {
}
}

bintocom {
name = "bbcbasic",
srcs = { "+bbcbasic_img" }
}
3 changes: 2 additions & 1 deletion third_party/bbcbasic/cmos.z80
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ OSINIT: LD C,45 ;*
; JP PE,SUM
; OR E
; JR NZ,BADSUM
XOR A
LD B,INILEN
LD HL,TABLE
CLRTAB: LD (HL),A ;CLEAR FILE TABLE ETC.
Expand Down Expand Up @@ -1473,4 +1474,4 @@ OPTVAL: DEFB 0
INILEN EQU $-TABLE
;
FIN: END


11 changes: 8 additions & 3 deletions third_party/bbcbasic/exec.z80
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ CHAIN0: LD SP,(HIMEM)
CALL LOAD0
RUN0: LD SP,(HIMEM) ;PREPARE FOR RUN
LD IX,RANDOM
RAND: LD A,R ;RANDOMISE (CARE!)
JR Z,RAND
; dtrg: bugfix here; on emulators, R is always zero, and the original
; code always waiting until it was non-zero, resulting in a hang.
; Instead we crudely hack around it.
ld a, r
jr nz, .1
inc a
.1
RLCA
RLCA
LD (IX+3),A
Expand Down Expand Up @@ -2864,4 +2869,4 @@ LF EQU 0AH
CR EQU 0DH
;
FIN: END


104 changes: 54 additions & 50 deletions third_party/bbcbasic/patch.z80
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ INIT: ;CALL INTIME ;INITIALISE TIMER
;REBOOT - Stop interrupts and return to CP/M.
;
REBOOT: LD A,3
OUT (CTC0+3),A
; OUT (CTC0+3),A
RST 0

;
Expand Down Expand Up @@ -173,60 +173,64 @@ WAIT1: CP (HL)
; Destroys: A,D,E,H,L,F
;
;
PCSR: LD A,E
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL ;*16
LD D,H
LD E,L
ADD HL,HL
ADD HL,HL
ADD HL,DE ;*80
LD D,0
LD E,A
ADD HL,DE ;OFFSET FROM HOME
LD DE,(HOME)
ADD HL,DE
LD A,14
OUT (CRTCS),A
LD A,H
AND 0FH
OUT (CRTCD),A
LD A,15
OUT (CRTCS),A
LD A,L
OUT (CRTCD),A
RET
PCSR: RET
; LD A,E
; ADD HL,HL
; ADD HL,HL
; ADD HL,HL
; ADD HL,HL ;*16
; LD D,H
; LD E,L
; ADD HL,HL
; ADD HL,HL
; ADD HL,DE ;*80
; LD D,0
; LD E,A
; ADD HL,DE ;OFFSET FROM HOME
; LD DE,(HOME)
; ADD HL,DE
; LD A,14
; OUT (CRTCS),A
; LD A,H
; AND 0FH
; OUT (CRTCD),A
; LD A,15
; OUT (CRTCS),A
; LD A,L
; OUT (CRTCD),A
; RET
;
;GCSR - Return cursor coordinates.
; Outputs: DE = X coordinate (POS)
; HL = Y coordinate (VPOS)
; Destroys: A,D,E,H,L,F
;
GCSR: LD A,14
OUT (CRTCS),A
IN A,(CRTCD)
LD H,A
LD A,15
OUT (CRTCS),A
IN A,(CRTCD)
LD L,A
LD DE,(HOME)
SBC HL,DE
LD A,H
AND 7
LD H,A
LD DE,-80
LD A,D
ROWS: ADD HL,DE
INC A
JR C,ROWS
SBC HL,DE
LD D,0
LD E,A
EX DE,HL
RET
GCSR: ld de, 0
ld hl, 0
ret
; LD A,14
; OUT (CRTCS),A
; IN A,(CRTCD)
; LD H,A
; LD A,15
; OUT (CRTCS),A
; IN A,(CRTCD)
; LD L,A
; LD DE,(HOME)
; SBC HL,DE
; LD A,H
; AND 7
; LD H,A
; LD DE,-80
; LD A,D
;ROWS: ADD HL,DE
; INC A
; JR C,ROWS
; SBC HL,DE
; LD D,0
; LD E,A
; EX DE,HL
; RET
;
TIME: DEFS 4
;
Expand Down Expand Up @@ -256,4 +260,4 @@ CRTCD EQU 85H
DEFB 'A' AND 1FH ;INSERT CHARACTER
;
FIN: END