diff --git a/README.md b/README.md index 87cc4db..a6dbc3d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Ever wondered how your *pron* stash would have looked on floppy disk? Try it out with HypraFap! -With HypraFap you can store and view 16 beautiful color images per disk side on your Commodore 64! +With HypraFap you can store and view about 16 beautiful color images per disk side on your Commodore 64! ![](img/3.png) @@ -76,6 +76,11 @@ You can directly select an image by pressing its number/letter. Press `5` to jum Press `0` or `i` (as in index) to jump back to the index image. +Now press `F3` to switch to the second screen and load image number 3 by pressing `3`. + +![](img/10.jpg) + +You then can switch back to screen 1 (with the index) by pressing `F1`. Jump back and forth between both screens. Everytime you press an image number or space, hyprafap loads the image to the currently selected screen. While loading the next screen the old image is visible and you can see how it is overwritten with new image data. This is intentional (you know HypraFap is doing something). @@ -88,23 +93,26 @@ See here how the next image is faintly visible on the top half (a face in the mi ![](img/1.jpg) +If you load a compressed Koala image (`.gg`), you cannot see how it is loaded because the data is loaded off screen to a buffer for decompressing. + ## Swap Disk If you have multiple disks with images, you can swap a disk out anytime while no drive access happens. Press `R` to reload the directory of the new disk and access the images on it. +Also, when you start HypraFap as a standalone `.prg` in VICE and thus no image is loaded at startup, use `R` to switch to and load an image disk. + # Keyboard Commands | key | command | |---|---| -| `0`-`9`, `A`-`F`| Load image 0..15| -| `I` | Load first image / number 0 (index / gallery)| +| `0`-`9`, `A`-`H`| Load image 0..17 to current screen| +| `I` | Load first image / number 0 (index / gallery) to current screen| | `Space` | next image | -| `R` | Reload directory after disk swap. Loads first image on new disk| - - -![](img/10.jpg) +| `R` | Reload directory after disk swap. Loads first image on new disk to current screen| +| f1 | Switch to screen 1| +| f3 | Switch to screen 2| # Making your own HypraFap disks @@ -118,6 +126,8 @@ HypraFap uses standard uncompressed Koala Painter images produced by a lot of pr to convert `.jpg` / `.png` files to `.koa` files. +You can also use RLE-compressed Koala Painter images (`.gg`), which you can convert from `.koa` files with different programs like [Pixcen](https://csdb.dk/release/?id=149752). This will typically make room for 1 more image per disk side. + ### Image aspect ratio Note that the pixels are not perfectly square on a C64. @@ -145,13 +155,13 @@ See how the Demo Disk looks like: ![](img/directory.png) -Images *need* to have the name ending in `.koa` for HypraFap to recognize them! +Images *need* to have the name ending in `.koa` (uncompressed) or `.gg` (compressed) for HypraFap to recognize them! -Add up to 16 Koala images per disk! +Add up to 16 Koala images per disk uncompressed or 17-18 compressed! ## Index image template -Index pages are just koala pictures like all the other pictures on the disks. An index images has to be the first image in the directory with the ending `.koa`. +Index pages are just koala pictures like all the other pictures on the disks. An index images has to be the first image in the directory with the ending `.koa` or `.gg`. You can use this template for your index image: @@ -182,6 +192,46 @@ If you have the linux bin in the same directory (src) as the `.asm` files run: to compile HypraFap. +# Technical specification of the Compressed Koala Painter Format (.gg) + +> :eggplant: :sweat_drops: *Note: This is retrived through reverse engineering* + +Koala Painter files with extension .gg are RLE compressed as follows: + +Starting at byte number 3 to skip the first two load address bytes ($00 $60), if 3 or more bytes are identical, these are replaced by + +`$FE [identical byte] [number of repetitions]` + +`[number of repetitions]` can be between $00 and $FF ($00 represents 256 repetitions) + +If $FE is found in the source bytes it is compressed, even when it only occures one time (one occurents of $FE results in bytes: `$FE $FE $01`). This can in rare occurences make the file larger than uncompressed. + +The load address' second byte $60 is not compressed even when several $60 bytes follow. Only the bytes starting at 3rd position are compressed -- thus only the image information is compressed! This makes sense as otherwise a load of a .gg file would fail in rare cases. + +(That $00 represents 256 repetitions is not mentioned in other documentations!) + +# Memory map of HypraFap + +| address | for Screen| Description| +|----|----|---| +|$0400|Screen 1|Screen RAM| +|$0801| |HypraFap program code| +|$2000|Screen 1|Bitmap| +|$3f40|Screen 1|Screen Data| +|$4328|Screen 1|Color Data| +|$4710|Screen 1|Color 0| +|$5c00|Screen 2|Screen RAM| +|$6000|Screen 2|Bitmap| +|$7f40|Screen 2|Screen Data| +|$8328|Screen 2|Color Data| +|$8710|Screen 2|Color 0| +|$9000|Buffer 1|RLE Load Buffer| +|$c320| |Number of images, other variables| +|$c581| |Directory entries| +|$d800| |Color RAM| + +See `headers.asm` for all labels in use. + # Know bugs & limitations - "Loading" message is written to screen ram, color changes in the old image partially when load is started. Since the old image is overwritten, that is not that of a problem. @@ -194,13 +244,35 @@ to compile HypraFap. |---------|---| |It is slow!| Yes, the data transfer between disk drive and computer is 400 bytes (!) per second. A 10kB Koala image takes about 25 seconds to load. You can speed this up with a fastloader, see above.| +# 📢 Community Support + +The [GitHub discussion boards](https://github.com/pronopython/hyprafap/discussions) are open for sharing ideas and plans for HypraFap. + +You can report errors through a [GitHub issue](https://github.com/pronopython/hyprafap/issues/new). + +Don't want to use GitHub? You can also contact me via email: pronopython@proton.me If you want to contact me anonymously, create yourself a burner email account. # Release Notes +## v0.2.0-alpha + +### added + +- 2 Screens available: Swicht between them with f1/f3 +- .gg file support with RLE decompression + +### changed + +- Pictures are now numbered 0-9,A-H (18 total) to accomodate 1 or 2 more pictures through RLE compression + +### fixed + +- Crash when no image is present on startup + ## v0.1.0-alpha - Initial Release # Why? -For me this is just a weekend fun project to learn a bit 6502 assembly language on an 8 bit computer :-) +For me this is just a weekend fun project to learn a bit 6502 assembly language on an 8 bit computer :-) \ No newline at end of file diff --git a/hyprafap.prg b/hyprafap.prg index 2a06ba5..507f1d2 100644 Binary files a/hyprafap.prg and b/hyprafap.prg differ diff --git a/hyprafap_demo_disk.d64 b/hyprafap_demo_disk.d64 index 09bc3d9..feb0eb7 100644 Binary files a/hyprafap_demo_disk.d64 and b/hyprafap_demo_disk.d64 differ diff --git a/src/control.asm b/src/control.asm index 3755763..5822a5b 100644 --- a/src/control.asm +++ b/src/control.asm @@ -35,8 +35,11 @@ cycle_images sta current_image loop_cycle_image - lda current_image - jsr load_image_by_number + lda number_of_images + beq no_images + lda current_image + jsr load_image_by_number + no_images cycle_images_scan_key_loop @@ -64,7 +67,8 @@ cycle_images jmp cycle_images_scan_key_loop check_letter - cmp #71 ; "g" (one after "f") + ;cmp #71 ; "g" (one after "f") + cmp #73 ; "i" (one after "h") bcc handle_letter ; == I == @@ -75,6 +79,12 @@ cycle_images cmp #82 ; "R" beq keypress_R + cmp #133 ; f1 + beq keypress_f1 + + cmp #134 ; f3 + beq keypress_f3 + jmp cycle_images_scan_key_loop ; no supported keypress ; == handle calculated keys (0-9,a-f) == @@ -111,7 +121,15 @@ cycle_images lda #0 sta current_image jmp loop_cycle_image - + + keypress_f1 + jsr show_screen_1 + jmp cycle_images_scan_key_loop + + keypress_f3 + jsr show_screen_2 + jmp cycle_images_scan_key_loop + check_biggest_image_number lda current_image sec @@ -125,13 +143,50 @@ cycle_images load_image_by_number ; A: image number (0..number of images - 1) ; uses $FB,$FC,$FD - sta $FD + + sta $FD ; remember image number + + tay + lda image_types, y + cmp #$0 + beq load_uncompressed + + lda #$3 ; load into buffer + sta $FE + + lda $FD + jsr get_filename_pointer + lda $FD + jsr calculate_image_filename_length + ldx $FB + ldy $FC + + jsr load_image + + lda active_shown_screen + jsr decompress_buffer + jsr show_selected_screen_after_load + + rts + + + load_uncompressed + + lda active_shown_screen + sta $FE + + lda $FD jsr get_filename_pointer lda $FD jsr calculate_image_filename_length ldx $FB ldy $FC + + jsr load_image + + jsr show_selected_screen_after_load + rts calculate_image_filename_length diff --git a/src/graphics.asm b/src/graphics.asm index 36b5b6b..b973894 100644 --- a/src/graphics.asm +++ b/src/graphics.asm @@ -40,12 +40,12 @@ init_multicolor sta 53270 lda #$78 ; 1c00 local start address for screen ram - sta 53272 + sta $d018 - lda 56576 + lda $dd00 and #252 ora #3-1 - sta 56576 + sta $dd00 rts @@ -54,80 +54,396 @@ clear_multicolor lda #$0 sta $d021 + jsr clear_screen_1 + jsr clear_screen_2 + jsr clear_color_data_1 + jsr clear_color_data_2 + jsr clear_color_ram + + + +clear_screen_1 ; clear bitmap ldy #$0 - tya - clear1 - sta bitmap_address,y - sta bitmap_address+$100,y - sta bitmap_address+$200,y - sta bitmap_address+$300,y - sta bitmap_address+$400,y - sta bitmap_address+$500,y - sta bitmap_address+$600,y - sta bitmap_address+$700,y - sta bitmap_address+$800,y - sta bitmap_address+$900,y - sta bitmap_address+$A00,y - sta bitmap_address+$B00,y - sta bitmap_address+$C00,y - sta bitmap_address+$D00,y - sta bitmap_address+$E00,y - sta bitmap_address+$F00,y - sta bitmap_address+$1000,y - sta bitmap_address+$1100,y - sta bitmap_address+$1200,y - sta bitmap_address+$1300,y - sta bitmap_address+$1400,y - sta bitmap_address+$1500,y - sta bitmap_address+$1600,y - sta bitmap_address+$1700,y - sta bitmap_address+$1800,y - sta bitmap_address+$1900,y - sta bitmap_address+$1A00,y - sta bitmap_address+$1B00,y - sta bitmap_address+$1C00,y - sta bitmap_address+$1D00,y - sta bitmap_address+$1E00,y + lda #$0 ;$0 / $1b = 00011011 all bit patterns + clear1_1 + sta bitmap_1,y + sta bitmap_1+$100,y + sta bitmap_1+$200,y + sta bitmap_1+$300,y + sta bitmap_1+$400,y + sta bitmap_1+$500,y + sta bitmap_1+$600,y + sta bitmap_1+$700,y + sta bitmap_1+$800,y + sta bitmap_1+$900,y + sta bitmap_1+$A00,y + sta bitmap_1+$B00,y + sta bitmap_1+$C00,y + sta bitmap_1+$D00,y + sta bitmap_1+$E00,y + sta bitmap_1+$F00,y + sta bitmap_1+$1000,y + sta bitmap_1+$1100,y + sta bitmap_1+$1200,y + sta bitmap_1+$1300,y + sta bitmap_1+$1400,y + sta bitmap_1+$1500,y + sta bitmap_1+$1600,y + sta bitmap_1+$1700,y + sta bitmap_1+$1800,y + sta bitmap_1+$1900,y + sta bitmap_1+$1A00,y + sta bitmap_1+$1B00,y + sta bitmap_1+$1C00,y + sta bitmap_1+$1D00,y + sta bitmap_1+$1E00,y iny - bne clear1 + bne clear1_1 ldy #$40 ; last 64 bytes of bitmap sec - clear2 + lda #$0 + clear2_1 dey - sta bitmap_address+$1F00,y - bne clear2 + sta bitmap_1+$1F00,y + bne clear2_1 ; clear screen ram (color 1,2) ldx #250 lda #$CF ; colors - clear3 - sta scrram-1,x - sta scrram+249,x - sta scrram+499,x - sta scrram+749,x + clear3_1 + sta screen_ram_1-1,x + sta screen_ram_1+249,x + sta screen_ram_1+499,x + sta screen_ram_1+749,x dex - bne clear3 + bne clear3_1 + rts - ; clear color ram (color 3) +clear_screen_2 + ; clear bitmap + ldy #$0 + lda #$0 ;e4 = 11100100 + clear1_2 + sta bitmap_2,y + sta bitmap_2+$100,y + sta bitmap_2+$200,y + sta bitmap_2+$300,y + sta bitmap_2+$400,y + sta bitmap_2+$500,y + sta bitmap_2+$600,y + sta bitmap_2+$700,y + sta bitmap_2+$800,y + sta bitmap_2+$900,y + sta bitmap_2+$A00,y + sta bitmap_2+$B00,y + sta bitmap_2+$C00,y + sta bitmap_2+$D00,y + sta bitmap_2+$E00,y + sta bitmap_2+$F00,y + sta bitmap_2+$1000,y + sta bitmap_2+$1100,y + sta bitmap_2+$1200,y + sta bitmap_2+$1300,y + sta bitmap_2+$1400,y + sta bitmap_2+$1500,y + sta bitmap_2+$1600,y + sta bitmap_2+$1700,y + sta bitmap_2+$1800,y + sta bitmap_2+$1900,y + sta bitmap_2+$1A00,y + sta bitmap_2+$1B00,y + sta bitmap_2+$1C00,y + sta bitmap_2+$1D00,y + sta bitmap_2+$1E00,y + iny + bne clear1_2 + + + ldy #$40 ; last 64 bytes of bitmap + sec + clear2_2 + dey + sta bitmap_2+$1F00,y + bne clear2_2 + + ; clear screen ram (color 1,2) + + ldx #250 + lda #$CF ; colors + clear3_2 + sta screen_ram_2-1,x + sta screen_ram_2+249,x + sta screen_ram_2+499,x + sta screen_ram_2+749,x + dex + bne clear3_2 + rts + +clear_color_ram + ; clear color ram (color 3) ldx #250 lda #$11 clear4 - sta colram-1,x - sta colram+249,x - sta colram+499,x - sta colram+749,x + sta color_ram-1,x + sta color_ram+249,x + sta color_ram+499,x + sta color_ram+749,x dex bne clear4 rts +clear_color_data_1 + ldx #250 + lda #$11 + clear_cd1 + sta color_data_1-1,x + sta color_data_1+249,x + sta color_data_1+499,x + sta color_data_1+749,x + dex + bne clear_cd1 + + lda #$0 + sta $4710 + + rts + +clear_color_data_2 + ldx #250 + lda #$11 + clear_cd2 + sta color_data_2-1,x + sta color_data_2+249,x + sta color_data_2+499,x + sta color_data_2+749,x + dex + bne clear_cd2 + + lda #$0 + sta $8710 + + rts + + set_background lda #$0 sta $d020 sta $d021 + rts + +show_selected_screen + lda active_shown_screen + cmp #$0 + beq set_screen_1 + jmp show_screen_2 + set_screen_1 + jmp show_screen_1 + +show_selected_screen_after_load + lda active_shown_screen + cmp #$0 + beq set_init_screen_1 + jmp init_screen_2 + set_init_screen_1 + jmp init_screen_1 + + + +show_screen_1 + +; switch video bank + lda $dd00 + and #$fc + ora #$3 + sta $dd00 + +; switch bitmap + screen ram + lda #$19 ;b00011001 + sta $d018 + +; load color 0 + lda $4710 + sta 53281 + + jsr copycolorram_screen_1 + + lda #$0 + sta active_shown_screen + + rts + + +show_screen_2 + +; switch video bank + lda $dd00 + and #252 + ora #3-1 + sta $dd00 + +; switch bitmap + screen ram + lda #$78 ; 1c00 local start address for screen ram + sta $d018 + +; load color 0 + lda $8710 + sta 53281 + + jsr copycolorram_screen_2 + + lda #$1 + sta active_shown_screen + + rts + + + +init_screen_1 + +; switch video bank + lda $dd00 + and #$fc + ora #$3 + sta $dd00 + +; switch bitmap + screen ram + lda #$19 ;b00011001 + sta $d018 + +; load color 0 + lda $4710 + sta 53281 + + jsr copycolorram_and_screenram_screen_1 + + lda #$0 + sta active_shown_screen + + rts + + +init_screen_2 + +; switch video bank + lda $dd00 + and #252 + ora #3-1 + sta $dd00 + +; switch bitmap + screen ram + lda #$78 ; 1c00 local start address for screen ram + sta $d018 + +; load color 0 + lda $8710 + sta 53281 + + jsr copycolorram_and_screenram_screen_2 + + lda #$1 + sta active_shown_screen + + rts + + + + +copycolorram_screen_1 + ldx #250 + loop_copy_color_screen_1 + lda color_data_1-1,x + sta color_ram-1,x + lda color_data_1+249,x + sta color_ram+249,x + lda color_data_1+499,x + sta color_ram+499,x + lda color_data_1+749,x + sta color_ram+749,x + + dex + bne loop_copy_color_screen_1 + + rts + +copycolorram_screen_2 + ldx #250 + loop_copy_color_screen_2 + lda color_data_2-1,x + sta color_ram-1,x + lda color_data_2+249,x + sta color_ram+249,x + lda color_data_2+499,x + sta color_ram+499,x + lda color_data_2+749,x + sta color_ram+749,x + + dex + bne loop_copy_color_screen_2 + + rts + +copycolorram_and_screenram_screen_1 + + ;lda 34576 + ;sta 53281 + + ldx #250 + loop_copy_colorram_and_screenram_1 + lda screen_data_1-1,x + sta screen_ram_1-1,x + lda screen_data_1+249,x + sta screen_ram_1+249,x + lda screen_data_1+499,x + sta screen_ram_1+499,x + lda screen_data_1+749,x + sta screen_ram_1+749,x + + lda color_data_1-1,x + sta color_ram-1,x + lda color_data_1+249,x + sta color_ram+249,x + lda color_data_1+499,x + sta color_ram+499,x + lda color_data_1+749,x + sta color_ram+749,x + + dex + bne loop_copy_colorram_and_screenram_1 + + rts + +copycolorram_and_screenram_screen_2 + + ;lda 34576 + ;sta 53281 + + ldx #250 + loop_copy_colorram_and_screenram_2 + lda screen_data_2-1,x + sta screen_ram_2-1,x + lda screen_data_2+249,x + sta screen_ram_2+249,x + lda screen_data_2+499,x + sta screen_ram_2+499,x + lda screen_data_2+749,x + sta screen_ram_2+749,x + + lda color_data_2-1,x + sta color_ram-1,x + lda color_data_2+249,x + sta color_ram+249,x + lda color_data_2+499,x + sta color_ram+499,x + lda color_data_2+749,x + sta color_ram+749,x + + dex + bne loop_copy_colorram_and_screenram_2 + rts \ No newline at end of file diff --git a/src/headers.asm b/src/headers.asm index 124a70b..377c338 100644 --- a/src/headers.asm +++ b/src/headers.asm @@ -31,18 +31,35 @@ number_of_images = $C320 current_image = $C321 -image_name_pointers = $C322 +last_load_end_address_low = $C322 +last_load_end_address_high = $C323 +active_shown_screen = $C324 +;... +image_name_pointers = $C325 ; space for 100 images... + +image_types = $C400 dir_length_high = $C581 ; high byte counter dir_length_low = $C582 ; low byte counter dir_start = $C583 ; write dir starting here +;bitmap 1 = screen 1 +bitmap_1 = $2000 +screen_data_1 = $3f40 +color_data_1 = $4328 +common_color_1 = $4710 ; also last byte of screen 1 +screen_ram_1 = $400 -bitmap_address = $6000 ; koala $6000 -scrdata = 32576 -coldata = 33576 -scrram = 23552 -colram = 55296 +;bitmap 2 = screen 2 +bitmap_2 = $6000 +screen_data_2 = 32576 +color_data_2 = 33576 +common_color_2 = $8710 ; also last byte of screen 2 +screen_ram_2 = 23552 +;color ram +color_ram = 55296 +;buffer 1 +buffer_1 = $9000 diff --git a/src/hyprafap.asm b/src/hyprafap.asm index 4fc180f..84611a1 100644 --- a/src/hyprafap.asm +++ b/src/hyprafap.asm @@ -43,6 +43,8 @@ jsr init_multicolor jsr clear_multicolor + jsr show_screen_1 + jsr cycle_images loop1 ; TODO remove this infinite loop (border color cycle) @@ -53,4 +55,5 @@ .include "waitkey.asm" .include "graphics.asm" .include "loadimage.asm" -.include "control.asm" \ No newline at end of file +.include "control.asm" +.include "rle.asm" \ No newline at end of file diff --git a/src/loaddir.asm b/src/loaddir.asm index e36bea5..025f7db 100644 --- a/src/loaddir.asm +++ b/src/loaddir.asm @@ -103,13 +103,17 @@ loaddir loop_dir_chars + ; === Test suffix === + cmp #46 ; . bne no_suffix jsr loaddir_store_acc_char + ; === Test koa === + jsr loaddir_getbyte cmp #75 ; K - bne no_suffix + bne test_gg ; test next suffix (gg) jsr loaddir_store_acc_char jsr loaddir_getbyte @@ -120,36 +124,59 @@ loaddir jsr loaddir_getbyte cmp #65 ; A bne no_suffix - jsr loaddir_store_acc_char ; match! - ; store beginning of current filename - lda number_of_images - clc - rol - tay - lda $FD - sta image_name_pointers, y - clc - iny - lda $FE - sta image_name_pointers, y - clc - iny - lda dir_length_low - sta image_name_pointers, y - clc - iny - lda dir_length_high - sta image_name_pointers, y - - ; inc number of images - clc - inc number_of_images - - ; save END - - jmp loop_end_name ; skip reset current mem pointer + lda #$0 ; image type koa + ldy number_of_images + sta image_types, y + + found_image_store_filename + ; store beginning of current filename + lda number_of_images + clc + rol + tay + lda $FD + sta image_name_pointers, y + clc + iny + lda $FE + sta image_name_pointers, y + clc + iny + lda dir_length_low + sta image_name_pointers, y + clc + iny + lda dir_length_high + sta image_name_pointers, y + + ; inc number of images + clc + inc number_of_images + + ; save END + + jmp loop_end_name ; skip reset current mem pointer + + ; === Test gg === + test_gg + + ;jsr loaddir_getbyte + cmp #71 ; G + bne no_suffix + jsr loaddir_store_acc_char + + jsr loaddir_getbyte + cmp #71 ; G + bne no_suffix + jsr loaddir_store_acc_char + + lda #$01 ; image type gg + ldy number_of_images + sta image_types, y + + jmp found_image_store_filename no_suffix diff --git a/src/loadimage.asm b/src/loadimage.asm index bd2eade..b77fef3 100644 --- a/src/loadimage.asm +++ b/src/loadimage.asm @@ -33,8 +33,14 @@ load_image ; A length filename ; X < image name ; Y > image name + ; $FE Bank (0: screen 1, 1: screen 2, 3: buffer 1) jsr $FFBD ; call SETNAM + + lda #$0 + sta last_load_end_address_low + sta last_load_end_address_high + lda #$01 ldx $BA ; last used device number bne no_last_device @@ -43,12 +49,33 @@ load_image ldy #$00 ; $00 means: load to new address jsr $FFBA ; call SETLFS - ldx #bitmap_address + ldx #bitmap_1 + lda $FE + cmp #$0 + beq set_image_ok + ldx #bitmap_2 + cmp #$1 + beq set_image_ok + ldx #buffer_1 + ; turn basic rom off + lda #$36 + sta $0001 + + set_image_ok + lda #$00 ; $00 means: load to memory (not verify) jsr $FFD5 ; call LOAD bcs error_image_load ; if carry set, a load error has happened - jmp copycolor ;RTS + stx last_load_end_address_low + sty last_load_end_address_high + ;jmp copycolor ;RTS + ; turn basic rom on + lda #$37 + sta $0001 + rts error_image_load ; Accumulator contains BASIC error code ; most likely errors: @@ -60,36 +87,35 @@ load_image ;TODO error handling ... rts +;copycolor -copycolor +; lda 34576 +; sta 53281 - lda 34576 - sta 53281 +; ldx #250 +; loop_copy_color +; lda screen_data_2-1,x +; sta screen_ram_2-1,x +; lda screen_data_2+249,x +; sta screen_ram_2+249,x +; lda screen_data_2+499,x +; sta screen_ram_2+499,x +; lda screen_data_2+749,x +; sta screen_ram_2+749,x - ldx #250 - loop_copy_color - lda scrdata-1,x - sta scrram-1,x - lda scrdata+249,x - sta scrram+249,x - lda scrdata+499,x - sta scrram+499,x - lda scrdata+749,x - sta scrram+749,x +; lda color_data_2-1,x +; sta color_ram-1,x +; lda color_data_2+249,x +; sta color_ram+249,x +; lda color_data_2+499,x +; sta color_ram+499,x +; lda color_data_2+749,x +; sta color_ram+749,x - lda coldata-1,x - sta colram-1,x - lda coldata+249,x - sta colram+249,x - lda coldata+499,x - sta colram+499,x - lda coldata+749,x - sta colram+749,x +; dex +; bne loop_copy_color - dex - bne loop_copy_color - - rts +; rts diff --git a/src/rle.asm b/src/rle.asm new file mode 100644 index 0000000..ce9b230 --- /dev/null +++ b/src/rle.asm @@ -0,0 +1,181 @@ +;---------------------------------------------------------------------------------------------- +; +; HypraFap - Retro Fapping System +; +; For updates see git-repo at +; https://github.com/pronopython/hyprafap +; +;---------------------------------------------------------------------------------------------- +; +; Copyright (C) PronoPython +; +; Contact me at pronopython@proton.me +; +; This program is free software: you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by the +; Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . +; +;---------------------------------------------------------------------------------------------- +; +; Turbo Macro Pro cross assembler code for Commodore 64 / 6502 CPU +; + +decompress_buffer + ; A destination screen + ; uses: f7, f8, f9, fa, fb, fc, fd, fe + + ; $F7 destinaton screen 0/1 + ; $F8 last destination byte + ; $FA byte to be repeated (temp) + ; $FB " + ; $FD " + + sta $f7 ; destinaton screen + + lda #buffer_1 + sta $fc + + lda #bitmap_1 + sta $fe + lda #common_color_1 + sta $f9 + + lda $f7 + cmp #$0 + beq bitmap1_destination + lda #bitmap_2 + sta $fe + lda #common_color_2 + sta $f9 + bitmap1_destination + + ; turn basic rom off + lda #$36 + sta $0001 + + rle_loop + + ; load next byte from buffer + ldy #0 + lda ($FB),y ; load from buffer + + cmp #$FE ; Run Length Encoding escape byte? + beq escape_found + + ldy #0 + sta ($fd),y ; store to screen + + ; check if done + clc + lda $fd + cmp $f8 + bcc advance_pointers_1 + lda $fe + cmp $f9 + bcc advance_pointers_1 + jmp exit_rle + + advance_pointers_1 + + inc $fd + bne done_inc_bitmap_pointer + inc $fe + done_inc_bitmap_pointer + + jsr increment_buffer + + jmp rle_loop + + escape_found + ; Escape Sequence for RLE is: + ;`$FE [identical byte] [number of repetitions]` + + jsr increment_buffer + + ldy #0 + lda ($fb), y ; load byte to be repeated ("identical byte") + sta $fa + + jsr increment_buffer + + ldy #0 + lda ($fb), y ; load number of repetitions + + tay + + lda $fa + + loop_repetitions + dey + + sta ($fd), y + + cpy #$0 + bne loop_repetitions + + ldy #0 + lda ($fb), y ; load number of repetitions, again + + cmp #$0 ; $0 in repetitions means 256 repetitions + beq inc_high + clc + adc $fd + sta $fd + bcc no_inc_high + + inc_high + inc $fe + no_inc_high + + ; check if done + clc + lda $fd + cmp $f8 + bcc advance_pointers_2 + beq advance_pointers_2 + lda $fe + cmp $f9 + bcc advance_pointers_2 + beq advance_pointers_2 + jmp exit_rle + + advance_pointers_2 + jsr increment_buffer + + jmp rle_loop + jmp exit_rle + + increment_buffer + inc $fb + bne done_inc_buffer_pointer_2 + inc $fc + done_inc_buffer_pointer_2 + rts + + exit_rle + ; turn basic rom on + lda #$37 + sta $0001 + rts \ No newline at end of file