Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Assembly and adding a Picture
2009-08-26 19:51
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Assembly and adding a Picture

Hi All,

I have some assembly code written for ACME assembler. I was just curious how I would add a picture into the code. I got the pause down but I just need a picture to show. Doesn't matter what format. I assume I can change my picture to most formats specified.

This would be great if someone could let me know.

Thanks,
MisterMSK
2009-08-26 20:49
Mace

Registered: May 2002
Posts: 1799
I'm not familiar with the ACME assembler, but in general adding a picture comes down to inserting/binding a binary file of that picture as an external file into your code.

In 64TASS is would be something like:
*=$2000
.binary "my picture.prg",2
2009-08-26 21:47
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
ACME:

*=address of pic
!bin "filename.prg",, $02
2009-08-27 03:39
TWW

Registered: Jul 2009
Posts: 541
And for actually showing the picture it depends totally wich format you are using.

But a Koala picture f.ex. is stored in video bank from $4000-8000.

It is a good format to get familiar with setting up gfx on the c64.

The bmp is from $6000 to $6e40 and immediately after you will find the char-colours and after that again you will find the $d800 colours.

which means you need to switch video bank ($dd00) and then set the correct video display ($d018) and then you need to copy the char colours into the video display you have selected in $d018. Lastly you need to copy the $d800 colours to....... $d800 :-)))))

alternatively you can transfer the bmp to $2000 - $3e40 and use $0400 and $d800 as normal.

You will find more about setting the video bank and $d018 in the programmers reference manual. And if I am not misstaken you will probably find 1000+ koala display routines on the net :) try a google!
2009-08-27 06:09
Angel of Death

Registered: Apr 2008
Posts: 210
hmmmm...
Why don't you do it the old-fashioned way? Steal the code!
Maybe from this one:
Hello!
(Please Jan. Don't shoot me. I'm just joking. Stealing is wrong!)

:))
2009-08-27 09:44
Mace

Registered: May 2002
Posts: 1799
Quoting TWW

But a Koala picture f.ex. is stored in video bank from $4000-8000.

That's totally untrue in any cross platform assembler, as you can load the binary at any location you wish.

Again, I'm not familiar with ACME, but in 64TASS you're able to even load a certain part of a binary.
This means you could load the bitmap, the chars and the colours at different locations, breaking up the Koala structure of the original binary.

Think outside the box ;-)
2009-08-27 10:43
linde

Registered: Jul 2006
Posts: 47
I put my pictures immediately after the code and move it where it should be using a loop to keep the size down a bit. My bsessive mind can't really stand having a bunch of empty space between the pic and code.

PS. not recommended if you're not using an assembler ;)
2009-08-27 13:37
enthusi

Registered: May 2004
Posts: 675
or do it the other way round - align the code to the gfx.
This way you save quite some memory to be overwritten:

*=$5c00

hirescolmap
.bin 8002,1000,"gfxfun/rooms2.ip64h"
.dsb 24,0
hiresbitmap
.bin 2,8000,"gfxfun/rooms2.ip64h"

code_start
	
init_gfx
	sei
	lda #$06
	sta $d020
	lda #%00000010
	sta $dd00
	lda $d011
	ora #%00111000	;enable hires + screen on
	sta $d011	
	lda #%01111000  
	sta  $d018


PS: ip64h is interpaint HiRes - gimp with cbmplugs is able to export to this format ;-)
PPS: you could also put the code inside the 24 byte gap between bitmap and colormap but well....
2009-08-27 13:50
Mace

Registered: May 2002
Posts: 1799
Quoting linde
My obsessive mind can't really stand having a bunch of empty space between the pic and code.

Funny.
The empty space between the code and the picture probably crunches better than the code to move the picture.
So in the end you're crunched file might be longer ;-)

So, yeah, what enthusi said.
2009-08-27 15:02
Skate

Registered: Jul 2003
Posts: 490
If you are using ACME, check this out. my library (sk8viclib) is exactly what you need.

http://www.akaydin.com/sk8lib/

in examples folder, there is an example called "vic+mem_example". this should help.

p.s: this library is not complete and not updated for a few years. but I'll finish and release it someday.


2009-08-27 19:16
TWW

Registered: Jul 2009
Posts: 541
Quoting tww

But a Koala picture f.ex. is stored in video bank from $4000-8000.

Quoting mace

That's totally untrue in any cross platform assembler, as you can load the binary at any location you wish.

Again, I'm not familiar with ACME, but in 64TASS you're able to even load a certain part of a binary.
This means you could load the bitmap, the chars and the colours at different locations, breaking up the Koala structure of the original binary.

Think outside the box ;-)


Uhm... a "KOALA" picture isn't in the $4000-8000 bank???

My statement stands true, I mentioned nothing about relocating. Any nimbwitt knows that everything can be relocated.

MisterMSK wanted someone to explain to him how to display a picture. You do this by teaching him how the format of the gfx works and how to set up $dd00/d018/d016/d011. then you can start relocating and customize as you wish after you get that part!

think standard format & learning ;-)
2009-08-27 22:10
Skate

Registered: Jul 2003
Posts: 490
@TWW: My library is a middle way solution. He can put his graphic datas to anywhere allowed in the memory without understanding how dd00/d018/d016/d011 works. Of course this is only good for the first step.
2009-08-28 06:50
Mace

Registered: May 2002
Posts: 1799
Quoting TWW
MisterMSK wanted someone to explain to him how to display a picture.

Well, actually he wanted to know how to add a picture into the code.
This can either be explained as how to attach a picture's binary file into the assembly code in order to have it added to the final PRG after compiling *OR* as how to write a routine to display the picture.

I was answering the first, you are answering the second.

However, you're answer suggests that if you'd want to display a Koala picture, you have to assume it's in $4000-$7fff, which IMHO is not true if you're working cross platform. The file simply doesn't have a location, as you always have to set it in your code when attaching the binary.

You are right, that if you'd load the picture on a real machine ",8,1" you'd have it starting at $6000.
You also suggest transfering it, but this implicates that you'd have to physically move it in the memory after loading.
Both are not necessary if you add the picture in your assembly code the way I suggest.

Perhaps MisterMSK should respond to our suggestions, so we can see where we're going... ;-)
2009-08-28 15:03
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Quote: Quoting TWW
MisterMSK wanted someone to explain to him how to display a picture.

Well, actually he wanted to know how to add a picture into the code.
This can either be explained as how to attach a picture's binary file into the assembly code in order to have it added to the final PRG after compiling *OR* as how to write a routine to display the picture.

I was answering the first, you are answering the second.

However, you're answer suggests that if you'd want to display a Koala picture, you have to assume it's in $4000-$7fff, which IMHO is not true if you're working cross platform. The file simply doesn't have a location, as you always have to set it in your code when attaching the binary.

You are right, that if you'd load the picture on a real machine ",8,1" you'd have it starting at $6000.
You also suggest transfering it, but this implicates that you'd have to physically move it in the memory after loading.
Both are not necessary if you add the picture in your assembly code the way I suggest.

Perhaps MisterMSK should respond to our suggestions, so we can see where we're going... ;-)


Sure. I modified FMGPUCCRBRR to just start a program when it loads. This way I can easly start a PRG from my MMC Replay (Just comment out like 64-67 and it will auto start the program. Make every color 0 so you don't see any text displayed.) Anyway, I am auto-starting sd2brwse, which allows me to browse my uIEC card with my joystick. I found, thou, it starts up to fast for the uIEC. So I wanted to create a 3 to 4 second pause. Then I relized I need more like a 6 to 8 second pause so I know it starts up every time. This is when I'd desided it needed a picture in there. It would be nice to put it in the FMGPUCCRBRR program so if I wanted to switch, let say, to DraBrowse I could. This site contains a program to transfer JPEG to Koala. So with that being easy to do, I would like to try to stick a Koala pick in there and pause for 6 to 8 seconds.

I hope this helps.
2009-08-29 01:10
TWW

Registered: Jul 2009
Posts: 541
So what is your question?

How to include the koala file in your code and/or displaying it on the screen :)

I believe Jan Harries already wrote how to include binaries into ACME:

ACME:

*=address of pic
!bin "filename.prg",, $02

I haven't used this assembler meself but this should normaly not be a problem to figgure out through the assemblers documentation. Even to do a 'selective' loading of the binary file so the such as mace sais to let the assembler relocate it for you (If you for some reason want to do that).

For displaying the code you need to set up the character screen and graphics bank with $dd00/$d018. Then you need to load up the 2 char-multicolor colours onto the character screen you have chosen by setting $d018. $d016 sets single/multicolor mode and $d011 sets hires mode. and ultimately you need to load the last multicolor colors onto $d800.

as said b4 there are a million sources and stuff for this (but if youre to laze to figgure it out I am sure I could post an example for you).

For pausing for some seconds there are a variety of ways to do this. but think that a screen update is 50 times a econd (PAL) (60 in NTSC) so if you count the amount of screen scans you can easilly 'pause'.

ldy #seconds
ldx #$50/60 //PAL/NTSC
cpx $d012
bne *-3
dex
bne *-6
dey
bne *-11


or something like that (not tested but should work if your not depending on $d012 for other stuff).
2009-11-02 16:52
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Quote: So what is your question?

How to include the koala file in your code and/or displaying it on the screen :)

I believe Jan Harries already wrote how to include binaries into ACME:

ACME:

*=address of pic
!bin "filename.prg",, $02

I haven't used this assembler meself but this should normaly not be a problem to figgure out through the assemblers documentation. Even to do a 'selective' loading of the binary file so the such as mace sais to let the assembler relocate it for you (If you for some reason want to do that).

For displaying the code you need to set up the character screen and graphics bank with $dd00/$d018. Then you need to load up the 2 char-multicolor colours onto the character screen you have chosen by setting $d018. $d016 sets single/multicolor mode and $d011 sets hires mode. and ultimately you need to load the last multicolor colors onto $d800.

as said b4 there are a million sources and stuff for this (but if youre to laze to figgure it out I am sure I could post an example for you).

For pausing for some seconds there are a variety of ways to do this. but think that a screen update is 50 times a econd (PAL) (60 in NTSC) so if you count the amount of screen scans you can easilly 'pause'.

ldy #seconds
ldx #$50/60 //PAL/NTSC
cpx $d012
bne *-3
dex
bne *-6
dey
bne *-11


or something like that (not tested but should work if your not depending on $d012 for other stuff).


TWW,

Thanks so much for the information. Got the pausing down. However, still have been trying to figure out the displaying a picture. When looking at different examples, never could get one to display. If you could post an example as you said, I would be greatful.

Thanks,
MisterMSK
2009-11-02 20:01
Perplex

Registered: Feb 2009
Posts: 254
Quote: So what is your question?

How to include the koala file in your code and/or displaying it on the screen :)

I believe Jan Harries already wrote how to include binaries into ACME:

ACME:

*=address of pic
!bin "filename.prg",, $02

I haven't used this assembler meself but this should normaly not be a problem to figgure out through the assemblers documentation. Even to do a 'selective' loading of the binary file so the such as mace sais to let the assembler relocate it for you (If you for some reason want to do that).

For displaying the code you need to set up the character screen and graphics bank with $dd00/$d018. Then you need to load up the 2 char-multicolor colours onto the character screen you have chosen by setting $d018. $d016 sets single/multicolor mode and $d011 sets hires mode. and ultimately you need to load the last multicolor colors onto $d800.

as said b4 there are a million sources and stuff for this (but if youre to laze to figgure it out I am sure I could post an example for you).

For pausing for some seconds there are a variety of ways to do this. but think that a screen update is 50 times a econd (PAL) (60 in NTSC) so if you count the amount of screen scans you can easilly 'pause'.

ldy #seconds
ldx #$50/60 //PAL/NTSC
cpx $d012
bne *-3
dex
bne *-6
dey
bne *-11


or something like that (not tested but should work if your not depending on $d012 for other stuff).


That code won't pause as long as you'd like as it stands.
The reason is that when x becomes below a certain value,
the raster line comparison will be true several times per
frame ($d012 wraps around from $ff to $00 just a few lines
into the lower border).

Easily fixed though:

lda #$fb    // Lower border starts here
ldy #seconds
ldx #$50/60 //PAL/NTSC
cmp $d012
bne *-3
cmp $d012
beq *-3
dex
bne *-11
dey
bne *-16


Sorry about the nitpick. :)
2009-11-02 20:49
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: That code won't pause as long as you'd like as it stands.
The reason is that when x becomes below a certain value,
the raster line comparison will be true several times per
frame ($d012 wraps around from $ff to $00 just a few lines
into the lower border).

Easily fixed though:

lda #$fb    // Lower border starts here
ldy #seconds
ldx #$50/60 //PAL/NTSC
cmp $d012
bne *-3
cmp $d012
beq *-3
dex
bne *-11
dey
bne *-16


Sorry about the nitpick. :)


Well, sorry to nitpick even more but pausing in hex isn't the way to do it... :) #$50/60 vs. #50/60
2009-11-03 00:59
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Quote: Well, sorry to nitpick even more but pausing in hex isn't the way to do it... :) #$50/60 vs. #50/60

Actually, I used this:

         ldx #60*4  ;60 fps * 4 seconds 
         lda #128 
loop1 cmp $d012      ;check if the raster has reached line 128 
         bne loop1      ;no, so keep checking 
loop2 cmp $d012      ;if it has you want to make sure you dont catch it more than once per frame 
         beq loop2      ;so wait till it isn't 0 any more 
         dex 
         bne loop1      ;loop round 60*4 times



I got how to added the Koala pic to $2000 but what is a good code for displaying it?
2009-11-03 02:15
clonK
Account closed

Registered: Aug 2008
Posts: 65
Quote: Actually, I used this:

         ldx #60*4  ;60 fps * 4 seconds 
         lda #128 
loop1 cmp $d012      ;check if the raster has reached line 128 
         bne loop1      ;no, so keep checking 
loop2 cmp $d012      ;if it has you want to make sure you dont catch it more than once per frame 
         beq loop2      ;so wait till it isn't 0 any more 
         dex 
         bne loop1      ;loop round 60*4 times



I got how to added the Koala pic to $2000 but what is a good code for displaying it?


Isn't that basic stuff that you'd be better off learning for yourself?
Is http://codebase64.org/doku.php?id=base:displaying_a_picture_at_.. not what you are looking for?

Also see - http://tnd64.unikat.sk/
and - http://www.oldschool-gaming.com/c64_hex_files.php

Learn about VIC banks.
2009-11-03 15:46
Stranger
Account closed

Registered: Nov 2006
Posts: 6
MisterMSK;
Skate of Glance released some detailed tutorials about bitmap things
But unfortunately in Turkish :) But don't worry. I 'll try to explain it with his way.

Multicolor graphic mode has 3 important components.

Video = 1000 bytes =>$03e8 bytes
Color = 1000 bytes =>$03e8 bytes
Bitmap = 8000 bytes =>$1f40 bytes

We need to load a picture from $2000 to $4710
BITMAP = from $2000+$1F40= to $3F40
VIDEO = from $3f40+$03e8= to $4328
COLOR = from $4328+$03e8= to $4710
BACKGROUND COLOR= $4710

Now we must transfer datas to correct locations for displaying a picture

Default video ram is starting from $0400
Transfer 1000 bytes data from
$3f40 to $0400
$3f41 to $0401
etc...
loks like..

lda VIDEO,x
sta $0400,x
lda VIDEO+$100,x
sta $0500,x
lda VIDEO+$200,x
sta $0600,x
lda VIDEO+$2e8,x
sta $06e8,x

Default color ram is starting from $d800
Transfer 1000 bytes data from
$4328 to $d800
$4329 to $d801

lda COLOR,x
sta $d800,x
lda COLOR+$100,x
sta $d900,x
lda COLOR+$200,x
sta $da00,x
lda COLOR+$2e8,x
sta $dae8,x

Also bitmap data at already at right place b'coz we'll load picture from $2000

And ofcourse transfer background color
lda BACKGROUND ($4710)
sta $d021

We need to set bitmap mode on
with
lda#$3b
sta$d011

also multicolor mode
with
lda#$d8
sta$d016

when bitmap adress at $2000 and screen at default $0400
lda#$18
sta$d018

Some values :
Koala Painter Values:
Bitmap = $0000-$1f3f = 0-7999
Video = $1f40-$2327 = 8000-8999
Color = $2328-$270f = 9000-9999
Backgrnd = $2710 = 10000

Advanced Art Studio Values:
Bitmap = $0000-$1f3f = 0-7999
Video = $1f40-$2327 = 8000-8999
Color = $2338-$271f = 9016-10015
Backgrnd = $2329 = 9001



And finally koala shower:


!to "koala.prg",cbm

* = $0801
!byte $0b, $08, $00, $00, $9e, $32, $30, $36, $31, $00, $00, $00

PICTURE = $2000
BITMAP = PICTURE
VIDEO = PICTURE+$1f40
COLOR = PICTURE+$2328
BACKGROUND = PICTURE+$2710

* = $080d

sei
lda #$00
sta $d020 ; Border Color
lda BACKGROUND
sta $d021 ; Screen Color

; Transfer Video and Color
ldx #$00
.LOOP
; Transfers video data
lda VIDEO,x
sta $0400,x
lda VIDEO+$100,x
sta $0500,x
lda VIDEO+$200,x
sta $0600,x
lda VIDEO+$2e8,x
sta $06e8,x
; Transfers color data
lda COLOR,x
sta $d800,x
lda COLOR+$100,x
sta $d900,x
lda COLOR+$200,x
sta $da00,x
lda COLOR+$2e8,x
sta $dae8,x
inx
bne .LOOP
;
; Bitmap Mode On
;
lda #$3b
sta $d011
;
; MultiColor On
;
lda #$d8
sta $d016
;
; When bitmap adress is $2000
; Screen at $0400
; Value of $d018 is $18
;
lda #$18
sta $d018
jmp *

;File must be at same directory ofcourse
* = PICTURE
!binary "filename",,2
2009-11-03 18:00
clonK
Account closed

Registered: Aug 2008
Posts: 65
Also, http://project64.c64.org/misc/map64.zip is very valuable to me whilst learning.
I made loads of notes, studied those sites I linked to, read and read various manuals and built up a better understanding of the memory map of the C64.
It's invaluable to put some effort into doing this stuff (thinking) yourself and realising WHY certain things are done in order to learn.
I'm still uber-noob, but I know that refraining from asking others to solve every single problem I face is the BEST way to learn! Your brain will thank you for it.
2009-11-03 19:58
NecroPolo

Registered: Jun 2009
Posts: 231
Another coding über-noob here. This thread is a great help, all the essential hints and pieces of knowledge, explanations are here.

Although I have passed the part of understanding the way it works recently and hopefully I will be able to make my first simple one-file demo soon - I still appreciate the helpful attitude.

Respect for that, for all of you. That is the way the things should be.

NP
2009-11-11 18:15
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Quote: or do it the other way round - align the code to the gfx.
This way you save quite some memory to be overwritten:

*=$5c00

hirescolmap
.bin 8002,1000,"gfxfun/rooms2.ip64h"
.dsb 24,0
hiresbitmap
.bin 2,8000,"gfxfun/rooms2.ip64h"

code_start
	
init_gfx
	sei
	lda #$06
	sta $d020
	lda #%00000010
	sta $dd00
	lda $d011
	ora #%00111000	;enable hires + screen on
	sta $d011	
	lda #%01111000  
	sta  $d018


PS: ip64h is interpaint HiRes - gimp with cbmplugs is able to export to this format ;-)
PPS: you could also put the code inside the 24 byte gap between bitmap and colormap but well....


Just what everyone else said x 1000. Thanks a lot to all. Just a quick question. I tried converting the quoted text acme but I don't know what .dsb is in Acme. Anyone know off the top of there head?
2009-11-11 18:21
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Also, where do you get the cbm plugin for Gimp? I tried the CBM Plugin Registry with no luck.
2009-11-11 21:25
enthusi

Registered: May 2004
Posts: 675
http://packages.debian.org/source/lenny/cbmplugs

and .dsb 24,0
means 24 bytes of value 0.
In this case to fill up the gap between 40x25 and 2^10.

Cheers,
enthusi
2009-11-12 02:21
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Wow! Thanks!
2010-02-11 22:11
Aeko
Account closed

Registered: Nov 2008
Posts: 1
Strager: PERFECT !

I've reading and trying several routines for displaying koala images (exported from Proyect One) and this the one that have worked like a charm to me. The explanation is also very clear.

Thanks, thanks a lot.
2010-02-13 09:03
Martin Piper

Registered: Nov 2007
Posts: 634
I remember back in the day working out how to do this without any documentation on the file format.
The bitmap portion of the file is 40*25*8 bytes, the colour information is another 40*25*2 bytes. The trick was to use the editor to change one thing, save the file, compare the binary difference. Rinse and repeat until it is understood where the different data is.
2010-02-14 12:29
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
Or you can rip the code from Koala Painter :D
2010-02-19 04:08
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
@Stranger

You are great. That works. I can't believe it. I got one final problem. After displaying an image I want to go back to a BASIC TEXT Video mode. I removed the last JMP and I inserted a 3 second pause. I change to the charater set to 21, as well as 23, but I still get the below image. How do you transfer back?



Thanks for All the Help,
MisterMsk
2010-02-19 04:42
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Got it. Thanks for all the help.

    lda #%00011111
    sta $d011
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Acidchild/Padua
bugjam
megasoftargentina
Zeus
Cruft/The Tiger Team..
Guests online: 117
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Carrion  (9.8)
2 Joe  (9.8)
3 Duce  (9.8)
4 Mirage  (9.7)
5 Facet  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.074 sec.