Posted by Capitalist Consumer on December 12, 1999 at 4:12:31 PM I thought it'd be nice to have a "Hello World" tutorial. The easiest way to do this would be to draw the greeting and load it into the frame buffer, but I thought I'd like to make this a bit more interesting. I'd like to create a font table first. Before I go any further, has anyone found a way to access the OS code that prints the name of the game in the file section? Marcus? John? Alexander? (And as if I'm going to get an answer...Loren? You did say you were trying to add a text option to your control file format.) Alexander said he saw some code from an amateur in Japan who was able to fit something like 6 rows of text with 12 characters per row in the LCD screen. I decided to make this my goal. In order to get that many characters onto the screen, each character could only be four pixels tall and three pixels wide. I created a font for this, and encoded it in the following manner: A = 1110 ($E) 1010 ($A) 1110 ($E) 1010 ($A) B = 1110 ($E) 1110 ($E) 1010 ($A) 1110 ($E) Then I combined the two letter. A with B: E with E A with E E with A A with E EE, AE, EA, AE font: ;;First Half ;; A-H .byte $EE,$AE,$EA,$AE,$EC,$8A,$8A,$EC,$EE,$CC,$88,$E8,$EA,$8E,$AA,$EA ;; I-P .byte $82,$82,$8A,$8E,$A8,$C8,$C8,$AE,$EA,$EA,$AE,$AA,$EE,$AA,$AE,$E8 ;;Second Half ;; Q-X .byte $EE,$AA,$EE,$EC,$EE,$E4,$24,$E4,$AA,$AA,$AA,$E4,$AA,$A4,$E4,$EA ;; Y-9 .byte $AE,$EE,$48,$4E,$0E,$06,$02,$4E,$AE,$A2,$E2,$22,$E0,$A0,$E0,$20 Some numbers and letters are the same. There is also a period and a space. The total number of characters is 32. To represent each letter, I decided to use half a byte a piece. The extra bit needed is stored in a special byte. Each extra bit (exbit) byte represents eight letters, or the next four bytes. For example: ;;hello world. ;;00000110 1001 .byte $06, $74, $BB, $EF, $6E .byte $90, $1B, $3D, $00, $00 This table is placed directly underneath the font table. Here's the code I've used. Could someone take a look at it to see if there are any problems? Please be nice; I'm just an amateur! This program is exactly like Marcus's Tetris, except I deleted everything after "call clrscr" in the start function. (And yes, I kept the clrscr function.) Is any of that extra stuff necessary in order for this to work? Here are the variables I used: bitpos = $40 ;;Used as a counter and to store the bit position being checked in the extra bit (exbit) alcnta = $41 ;;Alphabet Letter Count A,(used to lookup the first letter) alcntb = $42 ;;Alphabet Letter Count B (used to lookup the second letter) lcdcount = $43 ;;Used to keep track of the number of lines displayed count = $44 ;;General counter for text table exbit = $45 ;;The Extra Bit hola = $46 ;;Used to determine if the alcnta is looking up the first half of the font table or the second half holb = $47 ;;Used to determine if the alcntb is looking up the first half of the font table or the second half grtmp = $48 ;;a temporary variable used to put the two letters together and plot them on the screen (Not mentioned: Memory address 2, pointer to the LCD frame buffer) start: mov #$a1,ocr mov #$09,mcr mov #$80,vccr clr1 p3int,0 clr1 p1,7 mov #$ff,p3 call clrscr letters: clr1 ocr,5 push 2 push acc push xbnk mov #$80, bitpos mov #$80, 2 xor acc st xbnk st alcnta st alcntb st lcdcount mov # mov #>font,trh mov #$40, count back3: ld count ldc st exbit back2: ld bitpos and exbit mov #$0, hola bnz .skiphola mov #$20, hola .skiphola: ld bitpos ror and exbit mov #$0, holb bnz .skipholb mov #$20, holb .skipholb: ld bitpos ror st bitpos inc count ld count ldc st alcnta and #$0F st alcntb and #$0E add alcntb add holb st alcntb ld alcnta ror ror ror ror and #$0F st alcnta and #$0E add alcnta add hola st alcnta back: ld alcnta and #$E ldc bn alcnta, 0, .skiprol rol rol rol rol .skiprol: and #$F0 st grtmp ld alcntb and #$E ldc bp alcntb, 0, .skipror ror ror ror ror .skipror: and #$0F add grtmp st @R2 ld lcdcount bne #$3, .nextlet call newline jmp back .nextlet: ld bitpos be #$80, .next8 jmp back2 .next8: inc count ld count bne #$49, .wait jmp back3 .wait: pop xbnk pop acc pop 2 set1 ocr, 5 call letters newline: ld 2 add #$6 st 2 and #$F bne #$C, .skipnline ld 2 add #$4 st 2 .skipnline: inc lcdcount inc alcnta inc alcntb ret Posted by Marcus Comstedt on December 12, 1999 at 5:30:59 PM In Reply to: Hello World Tutorial posted by Capitalist Consumer on December 12, 1999 at 4:12:31 PM Another quick note: It looks like your program does a "call letters" at the end. That's no good for two reasons. First, you've got a function calling itself without ever returning. This will cause the stack to overflow. Secondly, you can't just busy-loop around without checking the keys. If you don't handle the SLEEP and MODE keys, there won't be any way of quitting your program apart from removing the batteries. // Marcus Posted by Marcus Comstedt on December 12, 1999 at 5:20:36 PM In Reply to: Hello World Tutorial posted by Capitalist Consumer on December 12, 1999 at 4:12:31 PM >I'd like to create a font table first. Before I go any further, has anyone found a way to access the OS code that prints the name of the game in the file section? Marcus? John? Alexander? (And as if I'm going to get an answer...Loren? You did say you were trying to add a text option to your control file format.) The firmware font / rendering code is not accessible from game mode. You have to supply your own. It's not all that difficult though. >[...] Then I combined the two letter. > >A with B: > >E with E >A with E >E with A >A with E > >EE, AE, EA, AE A standard "trick" is to combine each character with itself instead. The font will become twice as large, but you won't have to do any shifting when drawing the characters (just and with $F0 for even columns and $0F or odd columns) so you'll get much better printing performance. >The total number of characters is 32. To represent each letter, I decided to use half a byte a piece. The extra bit needed is stored in a special byte. Each extra bit (exbit) byte represents eight letters, or the next four bytes. For example: > >;;hello world. >;;00000110 1001 >.byte $06, $74, $BB, $EF, $6E >.byte $90, $1B, $3D, $00, $00 This seems unneccesarily involved. A VMS game can be up to 65536 bytes in size, so do you really need to pack your string literals into 5 bits per char? If you use 8 bits per char, the total size of all your strings will only increase by 60%, and you'll be able to write .byte "HELLO WORLD." instead, which is much more readable... // Marcus