Skip to content

Commit

Permalink
Implement basic image viewer for background images
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Sep 11, 2024
1 parent 85e0a25 commit 38e86b9
Show file tree
Hide file tree
Showing 13 changed files with 1,436 additions and 12 deletions.
Binary file added artifacts/1.19.1414 alpha/BOSOS.8xp
Binary file not shown.
Binary file added artifacts/1.19.1414 alpha/BOSOS.rom
Binary file not shown.
Binary file added artifacts/1.19.1414 alpha/BOSOSPT2.BIN
Binary file not shown.
Binary file added artifacts/1.19.1414 alpha/BOSOSpt2.8xv
Binary file not shown.
Binary file added artifacts/1.19.1414 alpha/BOSUPDTR.BIN
Binary file not shown.
1,244 changes: 1,244 additions & 0 deletions artifacts/1.19.1414 alpha/bos_internal.inc

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions convert_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def convert(fnamein, fnameout, mode=None):
subprocess.run(["convimg"],cwd=tmp)
imgbin = os.path.join(tmp, "image.bin")
with open(imgbin,'rb') as f:
f.seek(2, 0)
# f.seek(2, 0)
data = f.read()
with open(imgbin,'wb') as f:
f.write(data)
Expand All @@ -47,11 +47,11 @@ def convert(fnamein, fnameout, mode=None):
data = f.read()
with open(fnameout, 'wb') as f:
if mode is None:
f.write(b'IMG\0')
f.write(b'FSI\0')
elif mode == "zx7":
f.write(b'IMG7')
f.write(b'FSI7')
elif mode == "zx0":
f.write(b'IMG0')
f.write(b'FSI0')
f.write(data)
size = f.tell()
print(f"Finished. Output size: {size} bytes")
Expand Down
2 changes: 1 addition & 1 deletion src/data/adrive/src/fs/bin/explorer/loadconfig.asm
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ str_fg2:=$-3
inc hl
inc hl
ex hl,de
db $21,"IMG"
db $21,"FSI"
or a,a
sbc hl,bc
jq z,.setbackgroundimg
Expand Down
168 changes: 168 additions & 0 deletions src/data/adrive/src/fs/bin/imgview.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
jr imgview_main
db "FEX", 0
imgview_main:
ld hl,-18
call ti._frameset
or a,a
sbc hl,hl
ld (ix-3),hl
ld (ix-6),hl
ld (ix-9),hl
ld a,(ix+6)
cp a,2
jr nc,.has_enough_args
ld hl,.infostr
call bos.gui_PrintLine
jq .exit
.has_enough_args:
call osrt.argv_1
ld (ix-12),hl ; file name
push hl
call bos.fs_GetFilePtr
jr nc,.file_found
push hl
ld hl,.str_file_not_found
call bos.gui_PrintLine
pop hl
jr .exit_no_clear
.file_found:
ld (ix-15),hl ; file data pointer
dec bc
dec bc
dec bc
dec bc
ld (ix-18),bc ; file size-4
pop bc
ld bc,._waitexit
push bc
ld de,(hl)
inc hl
inc hl
inc hl
ld a,(hl)
db $21, "FSI" ; ld hl,...
or a,a
sbc hl,de
jr z,.view_fsi
db $21, "SPT" ; ld hl,...
or a,a
sbc hl,de
jr z,.view_spt

pop bc
.formaterror:
ld hl,.str_formaterror
call bos.gui_DrawConsoleWindow
ld hl,3
jr .exit_no_clear
.exit:
call cls_main
or a,a
sbc hl,hl
.exit_no_clear:
ld sp,ix
pop ix
ret

._waitexit:
call .waitexit
jr .exit

.waitexit:
call bos.sys_WaitKeyCycle
cp a,ti.skEnter
ret z
cp a,ti.sk2nd
ret z
cp a,ti.skClear
ret z
jr .waitexit

.view_fsi:
ld hl,(ix-15)
inc hl
inc hl
inc hl
inc hl
push hl
ld hl,bos.LCD_BUFFER
push hl
cp a,'7'
jr z,.view_fsi7
cp a,'0'
jr z,.view_fsi0
or a,a
jr nz,.formaterror

pop bc,bc

.view_fsi_no_compression:
ld hl,(ix-15)
ld de,bos.LCD_VRAM
ld bc,(ix-18)
ldir
jr .draw_vram
.draw_vram_from_buffer:
call bos.gfx_BlitBuffer
.draw_vram:
ld hl,bos.LCD_VRAM
ld (ti.mpLcdUpbase),hl
ret

.view_fsi7:
call bos.util_Zx7Decompress
jr .view_fsi7_0_common

.view_fsi0:
call bos.util_Zx0Decompress
.view_fsi7_0_common:
pop bc,bc
ld de,bos.LCD_BUFFER
or a,a
sbc hl,de
ld (ix-18),hl ; decompressed size
jr .draw_vram_from_buffer

.view_spt:
xor a,a
call bos.gfx_SetDraw
ld hl,(ix-18) ; file length
ld bc,7 ; min size
or a,a
sbc hl,bc
jp c,.formaterror ; not enough file data
ld hl,(ix-15) ; file pointer
ld e,(hl)
inc hl
ld a,(hl)
ld d,a
ex hl,de
mlt hl
add hl,bc
or a,a
sbc hl,bc
jp z,.formaterror ; zero width/height image
ex hl,de
dec hl
dec hl
ld bc,0
cp a,bos.LCD_WIDTH/2
jr nc,.view_spt_1x
ld a,(hl)
cp a,bos.LCD_HEIGHT/2
jr nc,.view_spt_1x
.view_spt_2x:
call bos.gfx_Sprite2x
jr .draw_vram_from_buffer
.view_spt_1x:
call bos.gfx_Sprite
jr .draw_vram_from_buffer

.infostr:
db "imgview (file)",0

.str_formaterror:
db "Invalid image file format",0

.str_file_not_found:
db "File not found",0
5 changes: 5 additions & 0 deletions src/data/adrive/src/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fs_dir bin_dir
fs_sfentry mf_exe, "mf", "", f_system+f_subfile
; fs_sfentry if_exe, "if", "", f_system+f_subfile
fs_sfentry info_exe, "info", "", f_system+f_subfile
fs_sfentry imgview_exe, "imgview", "", f_system+f_subfile
fs_sfentry jump_exe, "jump", "", f_system+f_subfile
; fs_sfentry json_exe, "json", "", f_system+f_subfile
fs_sfentry ls_exe, "l", "", f_system+f_subfile
Expand Down Expand Up @@ -175,6 +176,10 @@ fs_file os_internal_subfiles
include 'fs/bin/info.asm'
end fs_subfile

fs_subfile imgview_exe, bin_dir
include 'fs/bin/imgview.asm'
end fs_subfile

fs_subfile random_exe, bin_dir
include 'fs/bin/random.asm'
end fs_subfile
Expand Down
2 changes: 1 addition & 1 deletion src/data/buildno.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.1314 alpha
1.19.1414 alpha
18 changes: 13 additions & 5 deletions src/gui/Input.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ gui_Input:
call ti._frameset
xor a,a
sbc hl,hl
ld (ix-3),hl
ld (ix-11),hl
ld (ix-3),hl ; input current length
ld (ix-11),hl ; cursor position
ld hl,(ix+6)
ld (hl),a
inc a
Expand Down Expand Up @@ -277,18 +277,26 @@ gui_Input:
sbc hl,bc
jr z,.dontpaste ; no room in buffer
push hl
ld hl,(ix+6)
add hl,bc ; buffer write offset
ld hl,(ix+6) ; buffer pointer
add hl,bc ; buffer write pointer
ex hl,de
pop bc ; characters remaining in buffer
ld hl,(copy_buffer)
add hl,bc
or a,a
sbc hl,bc
jr z,.dontpaste ; nothing to paste
push bc,hl,de
push de,bc,hl,de
call ti._strncpy
pop bc,bc,bc
call ti._strlen
ex hl,de
ld hl,(ix-11)
add hl,de
ld (ix-11),hl ; advance cursor
ld hl,(ix-3)
add hl,de
ld (ix-3),hl ; advance buffer length
.dontpaste:
jq .draw

Expand Down
1 change: 0 additions & 1 deletion src/util/Zx0Decompress.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ util_Zx0Decompress:
; -----------------------------------------------------------------------------
; ZX0 decoder by Einar Saukas & introspec
; "Turbo" version
; edited by Adam Beckingham to run from flash memory
; -----------------------------------------------------------------------------

._turbo:
Expand Down

0 comments on commit 38e86b9

Please sign in to comment.