Skip to content

Commit

Permalink
add drivenumber to fileselector config
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Feb 2, 2025
1 parent 5b58e5b commit 06ca68a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
3 changes: 1 addition & 2 deletions compiler/res/prog8lib/cx16/diskio.p8
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,11 @@ return_status:
@(messageptr) = 0

done:
cbm.CLRCHN() ; restore default i/o devices
cbm.CLOSE(15)
cbm.CLRCHN() ; restore default i/o devices
return list_filename

io_error:
cbm.CLOSE(15)
list_filename = "io error"
goto done
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/res/prog8lib/shared_cbm_diskio.p8
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,11 @@ _end jsr cbm.READST
@(messageptr) = 0

done:
cbm.CLRCHN() ; restore default i/o devices
cbm.CLOSE(15)
cbm.CLRCHN() ; restore default i/o devices
return list_filename

io_error:
cbm.CLOSE(15)
list_filename = "io error"
goto done
}
Expand Down
2 changes: 2 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
TODO
====

- diskio diskname / fileselector hangs or crashes on X16 when using drive 9 instead of 8

- for creating libraries, something like %jmptable( block.func1, block.func2, ... ) could be useful to create a compact jump table, and possibly generating extsub definitions as well. Problem: directives cannot span multiple lines atm.

- Make neo and atari targets external via configs? They are very bare bones atm so easier to contribute to if they're configurable externally? What about the pet32 target
Expand Down
6 changes: 3 additions & 3 deletions examples/c64/fileselector.p8
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
%zeropage basicsafe

; A "TUI" for an interactive file selector, that scrolls the selection list if it doesn't fit on the screen.
; Depends a lot on diskio routines, and uses the drive set in the diskio.drivenumber variable (usually just 8)

; TODO sort entries alphabetically? Or not, because C64/C128 directories tend to be not very large.


main {
sub start() {

;; fileselector.configure(1, 5, 5)
;; fileselector.configure(1, 5, 5, 8)
uword chosen = fileselector.select("*")
txt.nl()
if chosen!=0 {
Expand All @@ -39,10 +38,11 @@ fileselector {
uword name_ptr
ubyte num_visible_files

sub configure(ubyte column, ubyte row, ubyte max_entries) {
sub configure(ubyte column, ubyte row, ubyte max_entries, ubyte drivenumber) {
dialog_topx = column
dialog_topy = row
max_lines = max_entries
diskio.drivenumber = drivenumber
}

sub select(str pattern) -> uword {
Expand Down
2 changes: 1 addition & 1 deletion examples/cx16/fileselector/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all clean zip run

all: main.prg fselector.bin standalone.prg
all: main.prg fselector-a000.bin standalone.prg

clean:
rm -f main.asm main.vice* main.prg fselector.asm fselector.vice* fselector*.bin standalone.asm standalone.vice* standalone.prg
Expand Down
10 changes: 5 additions & 5 deletions examples/cx16/fileselector/fselector.p8
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

; A "TUI" for an interactive file selector, that scrolls the selection list if it doesn't fit on the screen.
; Returns the name of the selected file. If it is a directory instead, the name will start and end with a slash '/'.
; Functions in PETSCII mode and in ISO mode as well (no case folding in ISO mode!)
; Depends a lot on diskio routines, and uses the drive set in the diskio.drivenumber variable (usually just 8)
; Works in PETSCII mode and in ISO mode as well (no case folding in ISO mode!)

; TODO joystick control? mouse control?
; TODO keyboard typing; jump to the first entry that starts with that character? (but 'q' for quit stops working then, plus scrolling with pageup/down is already pretty fast)
Expand All @@ -24,7 +23,7 @@ main {
; making the first jump neatly be the required initialization routine
; for the library (initializing variables and BSS region).
; Btw, $4c = opcode for JMP.
$4c00, &fileselector.configure_types,
$4c00, &fileselector.configure,
$4c00, &fileselector.configure_appearance,
$4c00, &fileselector.select,
]
Expand All @@ -36,7 +35,7 @@ main {

fileselector {
; these buffer sizes are chosen to fill up the rest of the hiram bank after the fileselector code
const uword filenamesbuf_size = $ea0
const uword filenamesbuf_size = $e90
const ubyte max_num_files = 128

uword @shared filenamesbuffer = memory("filenames_buffer", filenamesbuf_size, 0)
Expand All @@ -54,8 +53,9 @@ fileselector {
uword name_ptr


sub configure_types(ubyte show_types) {
sub configure(ubyte drivenumber, ubyte show_types) {
; show_types is a bit mask , bit 0 = include files in list, bit 1 = include dirs in list, 0 (or 3)=show everything.
diskio.drivenumber = drivenumber
show_what = show_types
if_z
show_what = 3
Expand Down
16 changes: 11 additions & 5 deletions examples/cx16/fileselector/main.p8
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ main {
sub start() {
if diskio.load_raw("fselector-a000.bin", $a000) != 0 {
fselector.init()
;; fselector.config_types(fselector.TYPE_ALL)
fselector.config(8, fselector.TYPE_ALL)
uword filename = fselector.select("*")
txt.print("\n\n\n\n\nselected: ")
txt.print(filename)
txt.nl()
txt.print("\n\n\n\n\n")

if filename!=0 {
txt.print("selected: ")
txt.print(filename)
txt.nl()
} else {
txt.print("nothing selected or error.\n")
}
}
}
}
Expand All @@ -25,7 +31,7 @@ fselector {
extsub $a000 = init() clobbers(A)

; what entry types should be displayed (default=all)
extsub $a004 = config_types(ubyte types @A) clobbers(A)
extsub $a004 = config(ubyte drivenumber @A, ubyte types @Y) clobbers(A)

; configure the position and appearance of the dialog
extsub $a008 = config_appearance(ubyte column @R0, ubyte row @R1, ubyte max_entries @R2, ubyte normalcolors @R3, ubyte selectedcolors @R4) clobbers(A)
Expand Down
8 changes: 4 additions & 4 deletions examples/cx16/fileselector/standalone.p8
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

; A "TUI" for an interactive file selector, that scrolls the selection list if it doesn't fit on the screen.
; Returns the name of the selected file. If it is a directory instead, the name will start and end with a slash '/'.
; Functions in PETSCII mode and in ISO mode as well (no case folding in ISO mode!)
; Depends a lot on diskio routines, and uses the drive set in the diskio.drivenumber variable (usually just 8)
; Works in PETSCII mode and in ISO mode as well (no case folding in ISO mode!)

; TODO joystick control? mouse control?
; TODO keyboard typing; jump to the first entry that starts with that character? (but 'q' for quit stops working then, plus scrolling with pageup/down is already pretty fast)
Expand All @@ -19,7 +18,7 @@
main {
sub start() {
; some configuration, optional
fileselector.configure_settings(3, 2)
fileselector.configure_settings(8, 3, 2)
fileselector.configure_appearance(10, 10, 20, $b3, $d0)

; show all files, using just the * wildcard
Expand Down Expand Up @@ -59,8 +58,9 @@ fileselector {
uword name_ptr


sub configure_settings(ubyte show_types, ubyte rambank) {
sub configure_settings(ubyte drivenumber, ubyte show_types, ubyte rambank) {
; show_types is a bit mask , bit 0 = include files in list, bit 1 = include dirs in list, 0 (or 3)=show everything.
diskio.drivenumber = drivenumber
buffer_rambank = rambank
show_what = show_types
if_z
Expand Down

0 comments on commit 06ca68a

Please sign in to comment.