News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Simple 6502 assembly image converter

Started by LemonWizard, July 17, 2013, 12:49:31 AM

Previous topic - Next topic

LemonWizard

So. I began learning 6502 assembly on this website here: (login required)

I started figuring out the pixel placement commands. Some of the other commands I'm still having some issues with.
Some of the screen values are hard to store in a single value and I haven't figured out how to use the carry flag yet.

So I came up with this.
it's kinda neat.
I don't know if it would work on any other website.
What it does is it takes an image with white pixels and uses the white pixels as the ink colour, then it generates compatible assembly code
from the 32*32 pixel image to cause it to display in that webpage.
All the code has the memory addresses written directly into it instead of trying to use a routine and store the values.
This IS playbasic related so I thought I might post it here. an example image that works with it is also provided.
I think it's fun. There's a readme to with the link in it if you lose the description link here.
Have fun!

PlayBASIC Code: [Select]
; PROJECT : Image maker
; AUTHOR : ScrinOverHive
; CREATED : 7/16/2013
; EDITED : 7/16/2013
; ---------------------------------------------------------------------
myimage=loadnewfximage("bitty.bmp")
drawimage myimage , 0, 0, 0
dim image(32, 32)

x=getimagewidth(myimage)
y=getimageheight(myimage)

if x>32
print "image not compliant, make it 32 pixels"
waitkey
end
endif

if y>32
print "image not compliant, make it 32 pixels"
waitkey
end
endif

rendertoimage myimage

for tempx=1 to 32
for tempy=1 to 32

image(tempx, tempy)=point(tempx, tempy)
#print point(tempx, tempy)


next tempy
next tempx

command1$="LDY #$01"
writefile "FileFile.txt", 1
writestring 1, command1$
counter=512
for tempy=1 to 32
for tempx=1 to 32
value$=hex$(counter)
newvalue$=right$(value$, 3)
nextcommand$="STY $"+newvalue$
red=rgbR( image(tempx, tempy) )
green=rgbG( image(tempx, tempy) )
blue=rgbB( image(tempx, tempy) )

if red=255
if green=255
if blue=255

writestring 1, nextcommand$

endif
endif
endif



counter=counter+1
next tempx
next tempy
closefile 1





LemonWizard

Here's some code my program generated from an image of samus masked.


LDY #$01
STY $200
STY $201
STY $202
STY $203
STY $204
STY $205
STY $206
STY $207
STY $208
STY $213
STY $214
STY $215
STY $216
STY $217
STY $218
STY $219
STY $21A
STY $21B
STY $21C
STY $21D
STY $21E
STY $220
STY $221
STY $222
STY $223
STY $224
STY $225
STY $226
STY $227
STY $234
STY $235
STY $236
STY $237
STY $238
STY $239
STY $23A
STY $23B
STY $23C
STY $23D
STY $23E
STY $240
STY $241
STY $242
STY $243
STY $244
STY $245
STY $246
STY $255
STY $256
STY $257
STY $258
STY $259
STY $25A
STY $25B
STY $25C
STY $25D
STY $25E
STY $260
STY $261
STY $262
STY $263
STY $264
STY $265
STY $27B
STY $27C
STY $27D
STY $27E
STY $280
STY $281
STY $282
STY $29C
STY $29D
STY $29E
STY $2A0
STY $2A1
STY $2A7
STY $2AE
STY $2AF
STY $2B0
STY $2BC
STY $2BD
STY $2BE
STY $2C0
STY $2C1
STY $2C7
STY $2C8
STY $2C9
STY $2CA
STY $2CB
STY $2CC
STY $2CD
STY $2CE
STY $2CF
STY $2D0
STY $2DD
STY $2DE
STY $2E0
STY $2E7
STY $2E8
STY $2E9
STY $2EA
STY $2EB
STY $2EC
STY $2ED
STY $2EE
STY $2EF
STY $2FE
STY $300
STY $307
STY $308
STY $309
STY $30A
STY $30B
STY $30C
STY $30D
STY $30E
STY $30F
STY $31E
STY $328
STY $329
STY $32A
STY $32B
STY $32C
STY $33E
STY $348
STY $349
STY $34A
STY $34B
STY $35E
STY $37E
STY $39D
STY $39E
STY $3A0
STY $3BD
STY $3BE
STY $3C0
STY $3DC
STY $3DD
STY $3DE
STY $3E0
STY $3E1
STY $3FB
STY $3FC
STY $3FD
STY $3FE
STY $400
STY $406
STY $407
STY $41B
STY $41C
STY $41D
STY $41E
STY $420
STY $422
STY $423
STY $424
STY $426
STY $427
STY $428
STY $433
STY $434
STY $435
STY $436
STY $43B
STY $43C
STY $43D
STY $43E
STY $440
STY $442
STY $443
STY $444
STY $446
STY $447
STY $452
STY $453
STY $454
STY $455
STY $456
STY $457
STY $45C
STY $45D
STY $45E
STY $460
STY $462
STY $463
STY $464
STY $466
STY $473
STY $474
STY $475
STY $476
STY $477
STY $47C
STY $47D
STY $47E
STY $480
STY $482
STY $483
STY $484
STY $486
STY $494
STY $495
STY $496
STY $497
STY $49C
STY $49D
STY $49E
STY $4A0
STY $4A2
STY $4A3
STY $4A4
STY $4A6
STY $4B4
STY $4B5
STY $4BC
STY $4BD
STY $4BE
STY $4C0
STY $4C2
STY $4C3
STY $4C4
STY $4C6
STY $4D4
STY $4D5
STY $4DC
STY $4DD
STY $4DE
STY $4E0
STY $4E5
STY $4E6
STY $4F3
STY $4F4
STY $4F5
STY $4F6
STY $4FC
STY $4FD
STY $4FE
STY $500
STY $501
STY $505
STY $506
STY $507
STY $50D
STY $513
STY $514
STY $515
STY $516
STY $51C
STY $51D
STY $51E
STY $520
STY $521
STY $522
STY $523
STY $524
STY $525
STY $526
STY $527
STY $528
STY $52D
STY $52E
STY $533
STY $534
STY $535
STY $536
STY $537
STY $53C
STY $53D
STY $53E
STY $540
STY $541
STY $542
STY $543
STY $544
STY $545
STY $546
STY $547
STY $548
STY $549
STY $54D
STY $54E
STY $54F
STY $553
STY $554
STY $555
STY $556
STY $557
STY $558
STY $559
STY $55A
STY $55B
STY $55C
STY $55D
STY $55E
STY $560
STY $561
STY $562
STY $563
STY $564
STY $565
STY $566
STY $567
STY $568
STY $569
STY $56D
STY $56E
STY $56F
STY $573
STY $574
STY $575
STY $576
STY $577
STY $578
STY $579
STY $57A
STY $57B
STY $57C
STY $57D
STY $57E
STY $580
STY $581
STY $582
STY $583
STY $584
STY $585
STY $586
STY $587
STY $58E
STY $594
STY $595
STY $596
STY $597
STY $598
STY $599
STY $59A
STY $59B
STY $59C
STY $59D
STY $59E
STY $5A0
STY $5A1
STY $5A2
STY $5A3
STY $5A4
STY $5A5
STY $5A6
STY $5AE
STY $5B4
STY $5B5
STY $5B6
STY $5B7
STY $5B8
STY $5B9
STY $5BA
STY $5BB
STY $5BC
STY $5BD
STY $5BE
STY $5C0
STY $5C1
STY $5C2
STY $5C3
STY $5C4
STY $5C5
STY $5C6
STY $5CE
STY $5D4
STY $5D5
STY $5D6
STY $5D7
STY $5D8
STY $5D9
STY $5DA
STY $5DB
STY $5DC
STY $5DD
STY $5DE


here's the image it produces:
http://imgur.com/GY6UArU
I forgot to mention you have to replace the bitty.bmp image with your own if you want to achieve this effect.

kevin


What's the target system ?  as it's writing 'chunky' array, where as these systems use planar.


LemonWizard

Quote from: kevin on July 17, 2013, 01:00:07 AM

What's the target system ?  as it's writing 'chunky' array, where as these systems use planar.


Quote from: kevin on July 17, 2013, 01:00:07 AM

What's the target system ?  as it's writing 'chunky' array, where as these systems use planar.



Just that site. I don't really have it made for a target platform. And it only converts the images to assembly code it doesnt do any other functions yet.

kevin

#4

  Here's a version that outputs 2bit planar.    It assumes the display has a linear frame buffer (image where each pixel follows the next), so the resulting code (which is posted in the debug window)  wouldn't work on real hardware without modification.  

PlayBASIC Code: [Select]
myimage=loadnewfximage("bitty.bmp")

drawimage myimage , 400, 0, 0


// Address of frame buffer
Address=0
For ylp=0 to getimageheight(myimage)-1
Row$=""

rendertoimage MyImage
For xlp=0 to getimagewidth(myimage)-1 step 8

// convert 8 chunky 32bit pixels to 2bit planar
ThisByte=0
For Bitlp=0 to 7
ThisRGB=Point(Xlp+Bitlp,ylp) and $00ffffff
ThisByte+=Lsl32(ThisRGB<>0, 7-Bitlp)
next
Row$+=right$(bin$(ThisByte),8)

#print " LDY #$"+right$(hex$(Thisbyte),2)
#print " STY $"+right$(hex$(Address),4)
Address++

next
rendertoscreen
print Row$
next


Sync
waitkey





LemonWizard

#5

I don't really understand what the planar thing means.

kevin

#6
 Just google bitplanes.

http://en.wikipedia.org/wiki/Planar_%28computer_graphics%29

PlayBASIC examples,

Convert Bitplanes to Chunky pixels

C64 Styled Sprite Rendering Example

C64 Display Mock up


Emulator examples,

Kyruss is similar to the web site above, except it's built around a simplified 32bit 68000. 

 

monkeybot

ahh 6502,i had a CBM64 and used to use ASM back in the old days...nice!

kevin

   Had a look at the simulator and it uses byte per pixel, making it somewhat easier..    



 ldy #0

main:

  TYA
  LDX #$00
lp:
  Sta $200,x
  Sta $300,x
  Sta $400,x
  Sta $500,x

  inx
  bne lp

  iny
  tya
  cmp #16
  bne main

  brk



LemonWizard

Quote from: kevin on July 17, 2013, 11:46:33 AM
   Had a look at the simulator and it uses byte per pixel, making it somewhat easier..   



  ldy #0

main:

   TYA
   LDX #$00
lp:
   Sta $200,x
   Sta $300,x
   Sta $400,x
   Sta $500,x

   inx
   bne lp

   iny
   tya
   cmp #16
   bne main

   brk




o.0 You 1-upped me. LOL

LemonWizard

In relation to that site I posted Kevin, think you could modify the snake game and make it more flashy?
Hah! A challenge! :D ;) or if anyone else wants to give it a shot. I'll try later. I want to get better at asm. I always understood the basics of asm. But nothing beyond that.

kevin

#11
 well, what..do..ya..know...  didn't even know there was a snake game.  

Edit: it doesn't run particular fast here, but you could probably make a pong game out of the snake.

LemonWizard

Anyone else going to give this stuff a shot? i'm curious to see what people come up with.
I'm thinking later of making a playbasic to ASM converter for simple playbasic project.s.

maybe i'll build a tiny game maker thing that converts the resources and code to asm. that'd be kinda cool.

kevin

  Well, you'd be better off targeting a cpu where you don't have to reinvent the universe like 6809 or 68000.   The latter is easier to wrap your head around since they at least have 32bit registers and basic math operators (Mult/Div).  Kyruss contains  slightly scaled down 68000 assembler and time shared runtime environment, much the same as the web page here.  Except it's an locally running app.    It was build originally as virus wars styled host, but would actually make a useful test environment for people wanting to dip their toes into assembly.

 

LemonWizard

Quote from: kevin on July 21, 2013, 08:32:43 AM
  Well, you'd be better off targeting a cpu where you don't have to reinvent the universe like 6809 or 68000.   The latter is easier to wrap your head around since they at least have 32bit registers and basic math operators (Mult/Div).  Kyruss contains  slightly scaled down 68000 assembler and time shared runtime environment, much the same as the web page here.  Except it's an locally running app.    It was build originally as virus wars styled host, but would actually make a useful test environment for people wanting to dip their toes into assembly.

 


Oh neat. that's really awesome. Maybe I'll mess with it sometime :3