PLUS4-LOAD-BINARY-FILES-FROM-BASIC! --------------------------------------------------------------------------------------------------- TOOL: BASIC 3.5 and TURBO-ASSEMBLER-MACRO! and built-in ML-Monitor Language: BASIC and Assembly Extra: none Author: Misel Zivanovic Note: (C) 14th AUGUST 2026 - www.lived.ch, mzretro.ch --------------------------------------------------------------------------------------------------- THIS IS PROBABLY SOMETHING YOU WON'T WANNA MISS ANYMORE! AND SOME DRY THEORY {as a reminder}: This code below will install a program to load binary files {and assembly programs} to a memory locations you can define {as low/high byte} It is located at $0190 or decimal 400 {NOTE: It's a basic LOAD routine in assembler, no magic! Except, it's a good replacement for BLOAD} Per default {first SYS call} is loading an assembler program called "main0.bin" to memory from $2100 {in this case it will load our custom characters animation interrupt routine which can be started with SYS 8448} You could also load a binary data called "main1.bin" to any location. More about that further below! *************************************************************************************************** UPDATE INFORMATION: FIND EXTENDED/MODIFIED VERSION OF THIS BASIC CODE FURTHER BELOW! AND ALSO ON A FLOPPYU DISK {LoadBinaryFiles.d64} *************************************************************************************************** 100 rem assembler loader start 105 if peek(758)=126 then goto 165 110 print chr$(147):color 1,6,4 112 cl$=chr$(19)+chr$(17):poke 758,126 115 poke 65301,1:poke 65305,1 120 rem (c) www.mzretro.ch - august 125 rem (c) www.lived.ch - 2026 130 print "data transfer in progress!" 135 for n= 0 to 39:read d$:a=dec(d$) 140 print using "###"+cl$;39-n 145 poke 400+n,a:next 150 rem assembler loader end 155 : 160 rem basic start at $4000 165 if peek(759)=231 then goto 200 170 graphic 1,0:graphic 0:poke 759,231 180 rem new char set! 195 : 196 rem main basic program start 197 rem where you can start your game 198 rem or whatever you prefer! 200 print chr$(147):color 1,6,5 205 color 0,6,3:color 4,6,1 210 poke 65299,(peek(65299)and3)or56 215 poke 65298,peek(65298)and251 220 : 5000 end 5005 rem data world 5010 data a9,01,a2,08,a0,01,20,ba 5020 data ff,a9,09,a2,ac,a0,01,20 5030 data bd,ff,a9,00,a2,00,a0,21 5040 data 20,d5,ff,60,4d,41,49,4e 5050 data 30,2e,42,49,4e,ff,00,00 *************************************************************************************************** HOW CAN YOU LOAD MORE FILES THAN ONE? --------------------------------------------------------------------------------------------------- Default name is "main0.bin" and is loading our custom character set as an animation from $2100 - $22b7. Now imagine you would wanna load a screen {which is more practical than wasting memory when you have it as a part of the BASIC program} Basically, you could say: "main1.bin" = screen graphics and "main2.bin" will be color data. NOTE: If you have installed the BASIC binary loader, then you can use the custom characters to make your game level like i did. Check the screenshot! IMPORTANT: ENTER THE ML-MONITOR BEFORE YOU START DRAWING BECAUSE you will need the SAVE command "S" from there! I drew all level data from the line 3{0-2} up to 19{2-18} to have enough space to save everything, which is graphics and colors, with the ML-Monitor "S" command. {check screenshots again} All you need is here below to successfully master this task! GAME SCREEN START : $0c50 - $0f1f - low byte $50, dec 80 - high byte $0c {decimal 12} GAME COLOR MAP START : $0850 - $0af7 - low byte $50, dec 80 - high byte $08 {decimal 08} --------------------------------------------------------------------------------------------------- We will save a screen portion {$02d0, 720 bytes} - { WHICH YOU MUST DRAW FIRST! { AS DESCRIBED {line 3 or actually 2 } { because it is counted from 0,1,2 } { until 19! So end line is 18, which is 19 } { just do poke 3152,81 to get the start line } { then do poke 3871,81 to get the end line } **************************************************** {NOTE: you always save one byte more = end address!} **************************************************** from $0c50 {dec 3152} to $0f1f {dec 3871+1} = $0f20 {final end address} directly to a floppy disk COMMAND {in ML-Monitor}: s"main1.bin",8,0c50,0f20 --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- We will save the same color portion {$02a8 in size, 720 bytes} - WHICH YOU CAN ADD TO YOUR DRAWING! from $0850 {dec 2128} to $0af7 {dec 2807+1} = $0af8 {final end address} directly to a floppy disk COMMAND {in ML-Monitor}: s"main2.bin",8,0850,0af8 --------------------------------------------------------------------------------------------------- This must be adapted before we call SYS 400 --------------------------------------------------------------------------------------------------- The address $01b0, dec 432, is containing 0 in "main0.bin"! [note: 48=0, 49=1, 50=2 etc.] The address $01a5, dec 421, is low byte for the target {load to} address The address $01a7, dec 423, is high byte for the target {load to} address We know all addresses now and can proceed! --------------------------------------------------------------------------------------------------- HOW TO LOAD *** ADDITIONAL *** BINARY FILES! --------------------------------------------------------------------------------------------------- Example: After we have saved the screen in ML-Monitor with the SAVE command "s", here is how we can load that file back to memory! {NOTE: CHECK THE FULL LISTING BELOW!} 4000 rem load level 1 gfx 4001 rem name main1.bin 4002 poke 432,49: rem 1 4003 rem load to $0c50 4004 poke 421,80:rem start low byte 4005 poke 423,12:rem start high byte 4006 sys 400 4007 for a=1 to 200:next 4008 rem load level 1 color 4009 rem name main2.bin 4010 poke 432,50: rem 2 4011 rem load to $0850 4012 poke 421,80:rem start low byte 4013 poke 423,8: rem start high byte 4014 sys 400 4015 return 4016 rem end level 1 --------------------------------------------------------------------------------------------------- LOADING ROUTINE: ASSEMBLY LISTING WITH ADDRESSES and NAME from $01ac, main0.bin We need this to know where we can POKE things to get what we need! In case you want to change the start address from $0190 to somewhere else, DO NOT FORGET to update the POKE addresses accordingly! --------------------------------------------------------------------------------------------------- . 0190 a9 01 lda #$01 . 0192 a2 08 ldx #$08 . 0194 a0 01 ldy #$01 . 0196 20 ba ff jsr $ffba . 0199 a9 09 lda #$09 . 019b a2 ac ldx #$ac . 019d a0 01 ldy #$01 . 019f 20 bd ff jsr $ffbd . 01a2 a9 00 lda #$00 . 01a4 a2 00 ldx #$00 . 01a6 a0 21 ldy #$21 . 01a8 20 d5 ff jsr $ffd5 . 01ab 60 rts . 01ac 4d 41 49 eor $4941 . 01af 4e 30 2e lsr $2e30 . 01b2 42 ??? . 01b3 49 4e eor #$4e . 01b5 ff ??? *************************************************************************************************** /////////////////////////////////////////////////////////////////////////////////////////////////// HERE IS NOW OUR COMPLETE BASIC LISTING TO DEMONSTRATE HOW TO LOAD THE ASSEMBLER PROGRAM, GAME LEVEL GRAPHICS and THE COLOR MAP! *************************************************************************************************** LEGEND: main0.bin - Assembler Program - Animated/Static Custom Characters main1.bin - Game Level 1 - Graphics {screen lines 3 to 19} $0c50 - $0f1f {+1} main2.bin - Game Level 2 - Color Map {screen lines 3 to 19} $0850 - $0af7 {+1} Save commands in ML-Monitor {end address always +1} [INTERRUPT ROUTINE CAN REMAIN ACTIVE!] - SCREEN GRAPHICS : s"main1.bin",8,0c50,0f20 - COLOR MAP : s"main2.bin",8,0850,0af8 In order to use this BASIC/Assembler Combo Program below, you must also have this Floppy Disk which you can find on my website www.mzretro.ch or www.lived.ch DISK NAME: LoadBinaryFiles.d64 /////////////////////////////////////////////////////////////////////////////////////////////////// *************************************************************************************************** 100 rem assembler loader start 105 if peek(758)=126 then goto 165 110 rem basic start at $4000 115 graphic 1,0:graphic 0:poke 758,126 120 print chr$(147):color 1,10,3 125 cl$=chr$(19)+chr$(17) 130 poke 65301,1:poke 65305,1 135 rem (c) www.mzretro.ch - august 140 rem (c) www.lived.ch - 2026 145 print "data transfer in progress!" 150 for n= 0 to 39:read d$:a=dec(d$) 155 print using "###"+cl$;39-n 160 poke 400+n,a:next 165 rem load custom anim character 170 sys 400: rem call bload, main0.bin 175 rem assembler loader end 180 : 196 rem main basic program start 197 rem where you can start your game 198 rem or whatever you prefer to do! 200 print chr$(147):color 1,7,3 205 color 0,1:color 4,1 210 gosub 4000: rem get level 1 215 sys 8448: rem call main0.bin 220 rem charset @ $3800, read from ram 225 poke 65299,(peek(65299)and3)or56 230 poke 65298,peek(65298)and251 235 char1,0,21,"www-mzretro-ch-08-2026" 240 char1,0,22,"press any key to quit" 245 getkey a$ 255 end 260 : 4000 rem load level 1 gfx 4001 rem name main1.bin 4002 poke 432,49 4003 rem load to $0c50 4004 poke 421,80: rem start low byte 4005 poke 423,12:rem start high byte 4006 sys 400 4007 for a=1 to 200:next 4008 rem load level 1 color 4009 rem name main2.bin 4010 poke 432,50 4011 rem load to $0850 4012 poke 421,80: rem start low byte 4013 poke 423,8:rem start high byte 4014 sys 400 4015 return 4016 rem end level 1 5000 : 5005 rem data world 5006 rem bload to load binary files! 5010 data a9,01,a2,08,a0,01,20,ba 5020 data ff,a9,09,a2,ac,a0,01,20 5030 data bd,ff,a9,00,a2,00,a0,21 5040 data 20,d5,ff,60,4d,41,49,4e 5050 data 30,2e,42,49,4e,ff,00,00 5060 rem data end load binary files! *************************************************************************************************** /////////////////////////////////////////////////////////////////////////////////////////////////// *************************************************************************************************** --------------------------------------------------------------------------------------------------- IN CASE YOU ARE WONDERING WHY DO I NEED THIS LOADER AT ALL!? --------------------------------------------------------------------------------------------------- You could just load the main assembler program yourself with BASIC a few BASIC commands, right!? Sure, absolutely correct or maybe not so...??? I actually tried BASIC lines like this: list-130 100 load"anim",8,1 105 graphic 1,0:graphic 0 110 color 0,2,1:color 4,5,3:color 1,8,5 120 print chr$(147):rem new char set! And that is loading absolutely nothing! Can't tell if that is again the VICE Emulation problem, or general Commodore Plus/4 behavior! Maybe it just cannot load asembler programs {code} and it got stuck when you try that from within a BASIC line and not in DIRECT mode {because that is working fine as we all know} Commodore C128 BASIC 7.0 is offering BLOAD command to load binary files to memory. And there i just can do 100 BLOAD "anim" and it is immediately going where it should! Commodore Plus/4 BASIC 3.5 does not have this command! So making an assembly loader does make sense after all! It is a great help! ---------------------------------------------------------------------------------------------------