Skip to content

Commit

Permalink
Started implementing story file loading for X16
Browse files Browse the repository at this point in the history
  • Loading branch information
johanberntsson committed Feb 29, 2024
1 parent ce5a08a commit 3094007
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all: x16

x16:
ruby make.rb -s examples/dragontroll.z5 -t:x16 -v
ruby make.rb -s examples/dejavu.z3 -t:x16 -v
#acme --cpu 65c02 -o testx16.bin --format cbm -l temp/acme_labels.txt testx16.asm
# Need F12 to enter the debugger
#grep testscreen temp/acme_labels.txt
Expand Down
4 changes: 4 additions & 0 deletions asm/disk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ current_disks !byte $ff, $ff, $ff, $ff,$ff, $ff, $ff, $ff
boot_device !byte 0
ask_for_save_device !byte $ff

!ifdef TARGET_X16 {
nonstored_pages !byte 0
}

!ifdef TARGET_MEGA65 {

mega65io
Expand Down
49 changes: 48 additions & 1 deletion asm/ozmoo.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,9 @@ deletable_init_start
; pcrc: RAM in bank 1, RAM everywhere
c128_mmu_values !byte $0e,$3f,$7f
}
!ifdef TARGET_X16 {
x16_statmem_already_loaded !byte 0
}
!ifdef TARGET_MEGA65 {
.first_value = z_temp
.different_values !byte 0
Expand Down Expand Up @@ -1916,7 +1919,15 @@ deletable_init
sty boot_device ; Boot device# stored

!ifdef TARGET_X16 {
;TODO TODO
jsr x16_init_reu
jsr x16_load_header
lda #'X'
jsr $ffd2
jsr $ffd2
jsr $ffd2
- jmp -
;jsr calc_dynmem_size
; Header of game on disk is now loaded, starting at $a000 (banked memory)
}
!ifdef TARGET_MEGA65 {
jsr m65_init_reu
Expand Down Expand Up @@ -2618,14 +2629,50 @@ prepare_static_high_memory

} ; End of VMEM

!ifdef TARGET_X16 {
x16_init_reu
jsr check_reu_size
sta reu_banks
rts
}

!ifdef TARGET_MEGA65 {
m65_init_reu
jsr check_reu_size
sta reu_banks
rts
}

!ifdef TARGET_X16 {
x16_load_header
ldx #$00
stx reu_progress_bar_updates
inx
stx x16_reu_load_page_limit ; read only one page (the header)
stx x16_reu_enable_load_page_limit
bne ++ ; Always branch

x16_load_dynmem_maybe_statmem
ldx x16_statmem_already_loaded
beq ++ ; Statmem is not loaded => load entire zcode file
ldx nonstored_pages
stx x16_reu_load_page_limit
ldx #$ff ; Don't store value of nonstored_pages, since it's $00 if dynmem size is >= $fe00
stx x16_reu_enable_load_page_limit

++ lda #.zcodefilenamelen
ldx #<.zcodefilename
ldy #>.zcodefilename
jsr kernal_setnam ; call SETNAM
ldx #0 ; Start on page 0 (page 0 isn't needed for copy ops on MEGA65)
txa
jmp x16_load_file_to_reu ; in reu.asm

.zcodefilename
!pet "zcode,s,r"
.zcodefilenamelen = * - .zcodefilename
}
!ifdef TARGET_MEGA65 {
m65_load_header
ldx #$00
Expand Down
81 changes: 78 additions & 3 deletions asm/reu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,75 @@ reu_error
!pet 13,"REU error, disabled. [SPACE]",0


!ifdef TARGET_X16 {

x16_reu_load_page_limit = z_temp + 10 ; max page # to read
x16_reu_enable_load_page_limit !byte 0 ; respect page # limit or not
.x16_reu_load_address = object_temp
.x16_reu_page_count = z_temp + 11

x16_load_file_to_reu
; In: a,x: REU load page (0 means first address of Attic RAM)
; Returns: a: Number of pages loaded.
; Call SETNAM before calling this
; Opens file as #2. Closes file at end.

; Prepare for copying data to REU
stx .x16_reu_load_address ; Lowbyte of current page in REU memory
sta .x16_reu_load_address + 1 ; Highbyte of current page in REU memory

lda #2 ; file number 2
tay
ldx boot_device
jsr kernal_setlfs ; call SETLFS

jsr kernal_open ; call OPEN
bcc +
lda #ERROR_FLOPPY_READ_ERROR
jsr fatalerror
+
ldx #2 ; filenumber 2
jsr kernal_chkin ; call CHKIN (file 2 now used as input)

ldx #0
stx z_temp

johan
.next_bank
stx $0000
lda #$a0
sta z_temp + 1
- ldy #0
-- jsr kernal_readst
bne .file_copying_done
jsr kernal_readchar
sta (z_temp),y
iny
bne --

inc z_temp + 1
lda z_temp + 1
cmp #$c0
bne -

inx
jmp .next_bank

.file_copying_done
lda #$00
sta x16_reu_enable_load_page_limit
jsr kernal_chkin ; restore input to keyboard
lda #$02 ; filenumber 2
jsr kernal_close ; call CLOSE
lda .x16_reu_page_count
rts
}
!ifdef TARGET_MEGA65 {

m65_reu_load_page_limit = z_temp + 10
m65_reu_enable_load_page_limit !byte 0
m65_reu_load_page_limit = z_temp + 10 ; max page # to read
m65_reu_enable_load_page_limit !byte 0 ; respect page # limit or not
.m65_reu_load_address = object_temp
.m65_reu_memory_buffer = zp_temp + 2
.m65_reu_page_count = z_temp + 11
Expand Down Expand Up @@ -277,9 +342,19 @@ store_reu_transfer_params
reu_banks !byte 0

check_reu_size
; return REU size in multiples of 64 KB
; input: -
; output: a=number of 64 KB banks of REU memory
; side effects:
; used registers:

!ifdef TARGET_X16 {
; test banks until value won't change (memory not available)
; TODO: we know that 512 KB is available, but the emulator
; wraps around, so we cannot test by writing to $a000 how
; large the memory actually is. Is there a better method?
lda #8 ; 8 * 64 = 512 KB
rts

;TODO TODO
} else ifdef TARGET_MEGA65 {
; Start checking at address $08 00 00 00
Expand Down
6 changes: 5 additions & 1 deletion asm/screen.asm
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,11 @@ get_cursor

!ifndef Z4PLUS {

!ifdef TARGET_MEGA65 {
!ifdef TARGET_X16 {
sl_score_pos !byte 54
sl_moves_pos !byte 67
sl_time_pos !byte 64
} else ifdef TARGET_MEGA65 {
sl_score_pos !byte 54
sl_moves_pos !byte 67
sl_time_pos !byte 64
Expand Down
2 changes: 2 additions & 0 deletions make.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,10 @@ def add_boot_file(finaldiskname, diskimage_filename)

def play(filename, storyname)
if $target == "x16" then
system("grep johan temp/acme_labels.txt")
command = "cd #{filename} && ../#{$X16} -prg #{storyname} -run"
command += " -dump B" # Ctrl-S from the emulator to dump memory
command += " -debug"
#command += " -scale 2"
elsif $target == "mega65" then
if defined? $MEGA65 then
Expand Down

0 comments on commit 3094007

Please sign in to comment.