Skip to content

Commit

Permalink
removed inline strings, added error codes, moved debug tools to utili…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
johanberntsson committed May 22, 2018
1 parent 8abeded commit 92249a6
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 312 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ X64 := /usr/bin/x64 -warp

#all: dejavu
#all: dragon
#all: minform
all: testz3
all: minform
#all: testz3
#all: testz5

d64.czechz3:
Expand Down
2 changes: 1 addition & 1 deletion constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ datasette_buffer_end = $03fb

; --- BASIC rom routines ---
basic_printstring = $ab1e ; write string in a/y (LO </HI >)
basic_printinteger = $bdcd ; write integer value in a/y
basic_printinteger = $bdcd ; write integer value in a/x

; Trace information
z_trace_page = $cf00
Expand Down
3 changes: 1 addition & 2 deletions disk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ readblocks
; most likely errors:
; A = $05 (DEVICE NOT PRESENT)
jsr .close ; even if OPEN failed, the file has to be closed
lda #ERROR_FLOPPY_READ_ERROR
jsr fatalerror
!pet "floppy read error", 0

.cname !text "#"
cname_len = * - .cname

Expand Down
2 changes: 1 addition & 1 deletion memory.asm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ read_byte_at_z_address
lda (mempointer),y
rts
.too_high
lda #ERROR_MEMORY_OVER_64KB
jsr fatalerror
!pet "tried to access z-machine memory over 64kb", 0

read_word_at_z_address
; Subroutine: Read the contents of a two consequtive byte addresses in the Z-machine
Expand Down
6 changes: 3 additions & 3 deletions objecttable.asm
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ z_ins_get_prop
.proplength_not_two
cmp #0
bne .proplength_one_or_more
lda #ERROR_BAD_PROPERTY_LENGTH
jsr fatalerror
!pet "z_ins_get_prop bad length", 13, 0
.proplength_one_or_more
ldx .prop_result + 1
lda .prop_result
Expand Down Expand Up @@ -999,8 +999,8 @@ z_ins_put_prop
jsr newline
}
rts
+ jsr fatalerror
!pet "z_ins_put_prop bad length", 13, 0
+ lda #ERROR_BAD_PROPERTY_LENGTH
jsr fatalerror

parse_object_table
lda story_start + header_object_table ; high byte
Expand Down
6 changes: 3 additions & 3 deletions ozmoo.asm
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ load_header
cmp #8
beq +
}
lda #ERROR_UNSUPPORTED_STORY_VERSION
jsr fatalerror
!pet "unsupported story version", 0

+ ; check file length
; Start by multiplying file length by 2
Expand Down Expand Up @@ -162,8 +162,8 @@ load_dynamic_memory
ldx fileblocks + 1
cpx #>($D000 - story_start) ; don't overwrite $d000
bcc ++
+ jsr fatalerror
!pet "Out of memory", 0
+ lda #ERROR_OUT_OF_MEMORY
jsr fatalerror

; read the rest
++ ldx #>story_start ; first free memory block
Expand Down
284 changes: 11 additions & 273 deletions screen.asm
Original file line number Diff line number Diff line change
@@ -1,282 +1,20 @@
; screen update routines

.saved_a !byte 0
.saved_x !byte 0
.saved_y !byte 0

printinteger
; subroutine: print integer value using Basic routine
; input: a,x
; output:
; used registers: a
; side effects:
!zone {
pha
lda #%00110111
sta zero_processorports
pla
jsr basic_printinteger
lda #%00110110
sta zero_processorports
rts
}

space
; subroutine: print space
; input:
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
lda #$20
jsr kernel_printchar
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
z_ins_set_text_style
; TODO: Proper implementation!
rts

comma
; subroutine: print space
; input:
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
lda #44
jsr kernel_printchar
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
rts


newline
; subroutine: print newline
; input:
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
lda #$0d
jsr kernel_printchar
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
z_ins_split_window
; split_window lines
; TODO: implement me
rts

printx
; subroutine: print value stored in x register
; input: x
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
lda #$00
jsr printinteger
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
z_ins_set_window
; set_window window
; TODO: implement me
rts

printy
; subroutine: print value stored in y register
; input: y
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
tya
tax
lda #$00
jsr printinteger
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
z_ins_set_cursor
; set_cursor line column
; TODO: implement me
rts

printa
; subroutine: print value stored in a register
; input: a
; output:
; used registers:
; side effects:
php
sta .saved_a
stx .saved_x
sty .saved_y
tax
lda #$00
jsr printinteger
lda .saved_a
ldx .saved_x
ldy .saved_y
plp
rts

printstring
; input: x
; output:
; used registers:
; side effects:
!zone {
pha
lda #%00110111
sta zero_processorports
pla
jsr basic_printstring
lda #%00110110
sta zero_processorports
rts
}

print_following_string
; print text (implicit argument passing)
; input:
; output:
; used registers: a
; side effects:
!zone {
; usage:
; jsr print_following_string
; !pet "message",0
; uses stack pointer to find start of text, then
; updates the stack so that execution continues
; directly after the end of the text

; store the return address
; the address on stack is -1 before the first character
pla ; remove LO for return address
sta .return_address + 1
pla ; remove HI for return address
sta .return_address + 2

; print the string
- inc .return_address + 1
bne .return_address
inc .return_address + 2
.return_address
lda $0000 ; self-modifying code (aaarg! but oh, so efficent)
beq +
jsr kernel_printchar
jmp -

; put updated return address on stack
+ lda .return_address + 2
pha
lda .return_address + 1
pha
rts
}

print_trace
;!ifdef DEBUG {
jsr print_following_string
!pet 13,"last opcodes: (#, z_pc, opcode)",13,0
lda z_trace_index
sec
sbc #40
tay
ldx #0
.print_next_op
jsr printx
lda #$2c
jsr kernel_printchar
lda #$24
jsr kernel_printchar
lda z_trace_page,y
jsr .print_byte_as_hex
iny
lda z_trace_page,y
jsr .print_byte_as_hex
iny
lda z_trace_page,y
jsr .print_byte_as_hex
iny
lda #$2c
jsr kernel_printchar
lda #$24
jsr kernel_printchar
lda z_trace_page,y
jsr .print_byte_as_hex
lda #$0d
jsr kernel_printchar
iny
inx
cpx #10
bcc .print_next_op
bcs .print_no_more_ops

.print_byte_as_hex
stx zp_temp
pha
lsr
lsr
lsr
lsr
tax
lda .hex_num,x
jsr kernel_printchar
pla
and #$0f
tax
lda .hex_num,x
ldx zp_temp
jmp kernel_printchar
.hex_num
!pet "0123456789abcdef"
.print_no_more_ops
;}
rts

fatalerror
; print error (implicit argument passing)
; input:
; output:
; used registers: a,x,y
; side effects: resets the computer
!zone {
; usage:
; jsr fatalerror
; !pet "message",0
; uses stack pointer to find start of text,
; prints the error, then resets the computer

jsr print_following_string
!pet "fatal error: ", 0

; store the return address
; the address on stack is -1 before the first character
pla ; remove LO for return address
tax
pla ; remove HI for return address
tay
txa
jsr printstring ; print error

jsr print_trace
jsr kernel_readchar ; read keyboard
jmp kernel_reset ; reset
}

Loading

0 comments on commit 92249a6

Please sign in to comment.