Jump to content



2

[coleco] Hello World! ( assembly codes listing )


15 replies to this topic

#1 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,053 posts

Posted Mon Aug 9, 2010 9:14 AM

Yes, it's another famous "HELLO WORLD!" sample program.

This time, "HELLO WORLD!" for the ColecoVision game system!

If you like this program, please consider a reply to this message, or a vote for appreciation.

I know that some programmers are willing to code something for the ColecoVision but don't get much information regarding how to do it in assembler, so I gave it a try and this is my version of HELLO WORLD for getting started with ColecoVision programming with ColecoVision BIOS calls.

The following listing was done in order to play with it, to modify it and understand a few concepts, not only to be compiled and that's it. Put your name on the title screen, change the text to display and where to display it, etc.

Filled with ColecoVision BIOS calls, this listing is a good example of what programmers in the 80s was doing in their commercial ColecoVision games.

Have fun!

; COLECOVISION - HELLO WORLD!
; By Daniel Bienvenu, 2010
; To be compiled with TNIASM

; BIOS (SOME) ENTRY POINTS
CALC_OFFSET: equ $08c0
LOAD_ASCII: equ $1f7f
FILL_VRAM: equ $1f82
MODE_1: equ $1f85
PUT_VRAM: equ $1fbe
TURN_OFF_SOUND: equ $1fd6
WRITE_REGISTER: equ $1fd9
READ_REGISTER: equ $1fdc
WRITE_VRAM: equ $1fdf

; VRAM DEFAULT TABLES
VRAM_PATTERN: equ $0000
VRAM_NAME: equ $1800
VRAM_SPRATTR: equ $1B00
VRAM_COLOR: equ $2000
VRAM_SPRGEN: equ $3800

    fname "hello2.rom"
    cpu Z80         ; switch to Z80 mode
    
    org $8000
    
    ; HEADER
    db $aa,$55 ; use $55,$aa to avoid the default CV title screen
    dw 0,0,0,0
    dw Start
rst_8:
    reti
    nop
rst_10:
    reti
    nop
rst_18:
    reti
    nop
rst_20:
    reti
    nop
rst_28:
    reti
    nop
rst_30:
    reti
    nop
rst_38:
    reti
    nop
    jp Nmi
    
    db "HELLO WORLD!/PRINT ON SCREEN/2010"

    ; PROGRAM
Start:
    im 1
    
    ; CLEAR VIDEO MEMORY
    ld  hl,$0000
    ld  de,$4000
    xor a
    call FILL_VRAM
    
    ; INIT DEFAULT SCREEN GRAPHIC MODE 1
    call MODE_1

    ; NO SOUND
    call TURN_OFF_SOUND

    ; DEFAULT FONT TO VIDEO MEMORY
    call LOAD_ASCII
    
    ; COLOR WHITE ON BLACK BACKGROUND
    ld  hl,VRAM_COLOR ; COLOR TABLE
    ld  de,32
    ld  a,$f0 ; WHITE ON BLACK
    call FILL_VRAM

    ; PRINT "HELLO WORLD!" CENTERED AT THE TOP OF THE SCREEN
    ; FORMULA = (32 CHARS PER LINE - 12 CHARS TO OUTPUT) / 2 = 10    
    call Static_Offset ; or use Calculated_Offset
    call Write_HelloWorld ; or use Put_HelloWorld but make sure to not add VRAM NAME TABLE with the Offset
    
    ; 16KB VIDEO MEMORY, 16x16 NORMAL SPRITES, AND TURN ON SCREEN
    ld  bc,$01c2 ; $01e2 ; = AND ENABLE NMI EXECUTION
    call WRITE_REGISTER
    
TheEnd:
    jp  TheEnd
    
HelloWorld:
    db "HELLO WORLD!"

Static_Offset:
    ld  de,VRAM_NAME+10 ; VRAM NAME TABLE + OFFSET
    ret 

Calculated_Offset:
    ld  d,0 ; LINE = 0
    ld  e,10 ; COLUMN = 10
    call CALC_OFFSET ; OFFSET = 32 * D + E
    ld  hl,VRAM_NAME
    add hl,de
    ex  de,hl
    ret
    
Write_HelloWorld:
    ld  hl,HelloWorld
    ld  bc,12 ; COUNT
    jp WRITE_VRAM

Put_HelloWorld:
    ld  a,2 ; ID#2 = VRAM NAME TABLE
    ld  hl,HelloWorld
    ld  iy,12 ; COUNT
    jp PUT_VRAM

Nmi:
    ; RANDOM COLOR ON BLACK BACKGROUND
    ld  hl,VRAM_COLOR ; COLOR TABLE
    ld  de,32
    ld  a,r ; REFRESH MEMORY STATE USED AS A RANDOM VALUE
    and $f0 ; BLACK BACKGROUND
    call FILL_VRAM

    ; ABSOLUTELY NEEDED
    call READ_REGISTER
    retn

* Bonus *

The smallest ColecoVision program ever!

NOTE : I'm not responsible if you see nothing because you modded your ColecoVision BIOS chip or if you're using an emulator that doesn't support so damn small ROM files.

; COLECOVISION - HELLO WORLD!
; By Daniel Bienvenu, 2010
; To be compiled with TNIASM

    fname "hello.rom"
    cpu Z80         ; switch to Z80 mode
    
    org $8000
    
    db $aa,$55
    dw 0,0,0
Start:
    nop
    ret
    dw Start
    dw 0,0,0,0,0,0,0,0,0,0,0
    retn
    db "HELLO WORLD!/ /2010"

Edited by newcoleco, Mon Aug 9, 2010 9:30 AM.


#2 Pixelboy OFFLINE  

Pixelboy

    River Patroller

  • 3,598 posts
  • Location:Montreal, Canada

Posted Mon Aug 9, 2010 10:09 AM

Very cool! Thanks for the listings, I'll keep them in my archives, and I'll try them ASAP (which probably means early next year, as you know). :)

#3 goldenegg OFFLINE  

goldenegg

    Dragonstomper

  • 518 posts

Posted Mon Aug 9, 2010 10:57 AM

Great post! That first chunk of code has to be the longest Hello World app I've ever seen :)

#4 retroclouds OFFLINE  

retroclouds

    Stargunner

  • 1,095 posts
  • Location:Germany

Posted Mon Aug 9, 2010 1:30 PM

Thanks Daniel.

#5 Pixelboy OFFLINE  

Pixelboy

    River Patroller

  • 3,598 posts
  • Location:Montreal, Canada

Posted Mon Aug 9, 2010 1:57 PM

View Postgoldenegg, on Mon Aug 9, 2010 10:57 AM, said:

Great post! That first chunk of code has to be the longest Hello World app I've ever seen :)
It would be much longer if he had defined his own text font! As it is, he's just using the default font from the BIOS. :)

#6 youki OFFLINE  

youki

    Stargunner

  • 1,077 posts

Posted Tue Aug 10, 2010 8:22 AM

View PostPixelboy, on Mon Aug 9, 2010 1:57 PM, said:

View Postgoldenegg, on Mon Aug 9, 2010 10:57 AM, said:

Great post! That first chunk of code has to be the longest Hello World app I've ever seen :)
It would be much longer if he had defined his own text font! As it is, he's just using the default font from the BIOS. :)

It would be even much longer if he did'nt do BIOS Call.

Thanks Daniel for the code.

#7 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,053 posts

Posted Thu Aug 19, 2010 5:54 PM

I've made videos on my Youtube channel about "Hello World!" for the ColecoVision. I hope this will bring even more programmers to get involved to ColecoVision scene.

First - with ColecoVision title screen


Second - With ColecoVision bios calls


#8 retroillucid OFFLINE  

retroillucid

    River Patroller

  • 2,490 posts
  • CollectorVision Games - Publishing Homebrew
  • Location:Montreal, Canada

Posted Thu Aug 19, 2010 8:02 PM

I love this kind of video :lust:
That is a very good learning guide to step onto Colecovision Homebrewing
Thanks for sharing! :thumbsup: +1

Would be nice to have more videos like those one

#9 retroclouds OFFLINE  

retroclouds

    Stargunner

  • 1,095 posts
  • Location:Germany

Posted Fri Aug 20, 2010 2:05 AM

Thanks for sharing this Daniel. That's very cool :thumbsup:

Just wondering, is there a special reason why the tniASM cross assembler is used?
Or will other Z80 assemblers work as well, e.g. the MSX sjam assembler ?

#10 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,053 posts

Posted Fri Aug 20, 2010 8:04 AM

View Postretroclouds, on Fri Aug 20, 2010 2:05 AM, said:

Thanks for sharing this Daniel. That's very cool :thumbsup:

Just wondering, is there a special reason why the tniASM cross assembler is used?
Or will other Z80 assemblers work as well, e.g. the MSX sjam assembler ?
Short : It's the one I've decided to use.

Long : You can use the compiler that fits better for you, every single assembler does have their particularities including special syntax and keywords that makes them not compatible, but when you know one well it's a good idea to use it. And I know better TNIASM than SJASM which I was not aware of before. And with TNIASM, I find it very cool to simply drag'n drop the file on the assembler icon and get a rom file ready to use; no need for a batch file to deal with options to type in the command line, it's simply done, bam!


Norman Nithman used TASM (not turbo assembler but Table driven assembler) when he presented Tic Tac Toe and a few disassembled listings including Q*Bert to the Coleco fans in 1996. Why your question isn't about TASM instead of SJASM? TASM supports way more CPUs than SJASM and it was already used by a ColecoVision programmer.


I know since now that SJASM exists and some MSX programmers use it. They manage to deal with CONText as an IDE and use a batch file to compile and run their projects. In my devkit also I've manage to use a compiler, Hi-Tech C at first and now SDCC, with my libraries by using a batch files creator I've called CCI (for Coleco Compiler Interface). TNIASM don't need a batch file.
http://br.msx.org/forumtopic6173.html

#11 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,053 posts

Posted Fri Aug 20, 2010 11:53 PM

View Postretroillucid, on Thu Aug 19, 2010 8:02 PM, said:

I love this kind of video :lust:
...
Would be nice to have more videos like those one
Just for you then... another video. Enjoy!


Note : Remember that a typical not working cartridge is rather a mess on screen, or a "TURN GAME OFF" message. But with this program, you can make the ColecoVision looks like it doesn't work at all. ;-)

Edited by newcoleco, Fri Aug 20, 2010 11:55 PM.


#12 retroillucid OFFLINE  

retroillucid

    River Patroller

  • 2,490 posts
  • CollectorVision Games - Publishing Homebrew
  • Location:Montreal, Canada

Posted Sat Aug 21, 2010 10:57 AM

View Postnewcoleco, on Fri Aug 20, 2010 11:53 PM, said:

View Postretroillucid, on Thu Aug 19, 2010 8:02 PM, said:

I love this kind of video :lust:
...
Would be nice to have more videos like those one
Just for you then... another video. Enjoy!


Note : Remember that a typical not working cartridge is rather a mess on screen, or a "TURN GAME OFF" message. But with this program, you can make the ColecoVision looks like it doesn't work at all. ;-)

Thanks Daniel!
I do really appreciate those little videos :cool: +1

Now, time to give this a try ;)

#13 l@k OFFLINE  

l@k

    Combat Commando

  • 2 posts

Posted Thu Aug 26, 2010 10:57 AM

It's fabulous that you've put in so much effort in this and in all your works.
I'll try it on my FPGA coleco soon. (like your other music pieces)

lak.

#14 ColecoFan1981 OFFLINE  

ColecoFan1981

    Chopper Commander

  • 187 posts
  • Location:Milwaukie (Oak Grove), OR

Posted Mon May 9, 2011 3:39 AM

Sorry to bump this old of a thread, but...

How do code this ASM to make a longer title, one on two or three lines? For example: "PRESENTS NINTENDO'S DONKEY KONG" (on two lines)?

~Ben

#15 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,053 posts

Posted Mon May 9, 2011 11:42 AM

View PostColecoFan1981, on Mon May 9, 2011 3:39 AM, said:

Sorry to bump this old of a thread, but...

How do code this ASM to make a longer title, one on two or three lines? For example: "PRESENTS NINTENDO'S DONKEY KONG" (on two lines)?

~Ben

If you replace the "HELLO WORLD!/ /2010" by "DONKEY KONG/PRESENTS NINTENDO'S/1982" you get the effect you are looking for. Also, some other games try to write even more lines by adding spaces to artificialy add lines, but it's not normal usage.

And there is no problem to bring back this kind of thread, it contains programming information that new and not so new to ColecoVision programming may enjoy reading.

#16 ColecoFan1981 OFFLINE  

ColecoFan1981

    Chopper Commander

  • 187 posts
  • Location:Milwaukie (Oak Grove), OR

Posted Mon May 9, 2011 12:56 PM

View Postnewcoleco, on Mon May 9, 2011 11:42 AM, said:

View PostColecoFan1981, on Mon May 9, 2011 3:39 AM, said:

Sorry to bump this old of a thread, but...

How do code this ASM to make a longer title, one on two or three lines? For example: "PRESENTS NINTENDO'S DONKEY KONG" (on two lines)?

~Ben

If you replace the "HELLO WORLD!/ /2010" by "DONKEY KONG/PRESENTS NINTENDO'S/1982" you get the effect you are looking for. Also, some other games try to write even more lines by adding spaces to artificialy add lines, but it's not normal usage.

And there is no problem to bring back this kind of thread, it contains programming information that new and not so new to ColecoVision programming may enjoy reading.
Thank you, that worked!







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users