Overriding default ASCII values in strings?

  • Author
  • Message
Offline
User avatar

chickendude

Staff Member

Topic Starter

Overriding default ASCII values in strings?

Post26 November 2011, 21:26

Is there any way i could change the values of the characters in strings? So instead of space =$20 have space=$FE for example? I made a little converter in PHP to do it but all my texts look like this now:
textGO:
;You have passed GO, please collect $200.
.db 17,28,32,$FE,26,19,52,23,$FE,29,19,65,65,23,22,$FE,6,10,63,$FE,29,53,23,19,65,23,$FE,21,28,53,53,23,21,55,$FE,60,36,10,10,62,$FF
Offline
User avatar

NanoWar

Site Admin

Re: Overriding default ASCII values in strings?

Post27 November 2011, 12:20

So what you want is a php function that converts an input string to an specifically encoded hex representation. Easiest possible approach would be to put all characters in an array, search to the string and replace the characters.
But what's wrong with the TI font format? It's much easier, more readable and more flexible to just do .db "You just have passed GO", 0 and adjust the text drawing routine instead.
Offline
User avatar

chickendude

Staff Member

Topic Starter

Re: Overriding default ASCII values in strings?

Post27 November 2011, 12:53

I've already written a PHP routine. The problem is that i'm using a custom font and don't want to waste space on unnecessary characters. Do i really need Image, Image, Image, Image, etc.? My font is based on character width, so two 4-pixel-wide characters are drawn in the same sprite, a 5-pixel and 3-pixel together, four 2-pixels, etc. I think i could probably write something (is spasm written in C?) because i don't think it'd be too complicated, but i can't get spasm to compile, it appears i'm missing a few files.

For now, i think i'm just going to define some constants.
Offline
User avatar

NanoWar

Site Admin

Re: Overriding default ASCII values in strings?

Post27 November 2011, 20:04

Code: Select all
text:
.db "Just text", custom_letter, "more text", 0

... is very easy to implement with a custom text routine!
Offline
User avatar

NanoWar

Site Admin

Re: Overriding default ASCII values in strings?

Post28 November 2011, 10:24

Code: Select all
printText
; saves: de, bc
; destroys: ix
      ld    a, (hl)
      inc   hl
      or    a
      ret   z
      cp    inlineIcon_offset
      jr    nc, printText.specialchar
      push  de
            bcal _vPutMap
      pop   de
      ret   c
      jr    printText

printText.specialChar
      push  de
      push  bc
            sub   inlineIcon_offset -1 ; = sub offs + inc a
            ld    b, a
            ld    ix, inlineIcon_begin - inlineIcon_size
            ld    de, inlineIcon_size
_
            add   ix, de
            djnz  -_
            ; (ix) = icon_width
      pop   bc
      pop   de
      ld    a, (pencol)
      add   a, (ix)
      cp    95 ; end of line
      ret   nc
      push  de
      push  bc
      push  hl
            push  ix
                  inc   ix
                  ; ix = icon_data
                  ld    hl, (pencol)
                  ; l = col (x), h = row (y)
                  inc   h
                  ld    a, l
                  ld    l, h
                  ld    b, 5
                  call  smallSprite
            pop   hl
            ; (hl) = icon_width
            ld    b, (hl)
            ; b = icon_width
            ld    hl, pencol
            ld    a, (hl)
            add   a, b
            inc   a
            ld    (hl), a
            ; pencol = pencol + icon_width + 1
      pop   hl
      pop   bc
      pop   de
      jr    printText


Assume you want to overwrite font-values above 240:
Code: Select all
#define inlineIcon_offset 240
#define inlineIcon_size 1+5 ; width_byte + sprite_data

inlineIcon_begin
      .enumStart inlineIcon_offset

      .enum "icon_1"
      .db 5 ; width
      #include icons/icon_1.bmp ; always 5 pixel high icon

      .enum "icon_2"
      .db 3 ; width
      #include icons/icon_2.bmp ; always 5 pixel high icon

      .enumEnd 255
Offline
User avatar

chickendude

Staff Member

Topic Starter

Re: Overriding default ASCII values in strings?

Post28 November 2011, 11:59

The thing is, none of my letters match up to TIs ASCII font, not a single one. They aren't in the same order, either. And as i don't draw to the gbuf (because it is too small for my mapper i "created" a custom gbuf using i think saferam1 and part (or all?) of saferam2, storing the data in between those locations in saferam3 and restoring it when the program exits), TI's routines are no use at all to me.

Here's the alphabet in order:
Code: Select all
alfabeto:
#include "/images/alphabet/AB.bmp"  ;0 4x4
#include "/images/alphabet/CD.bmp"  ;1
#include "/images/alphabet/EF.bmp"  ;2
#include "/images/alphabet/GH.bmp"  ;3
#include "/images/alphabet/JK.bmp"  ;4
#include "/images/alphabet/OP.bmp"  ;5
#include "/images/alphabet/QR.bmp"  ;6
#include "/images/alphabet/SU.bmp"  ;7
#include "/images/alphabet/XY.bmp"  ;8
#include "/images/alphabet/Za.bmp"  ;9
#include "/images/alphabet/bc.bmp"  ;10
#include "/images/alphabet/de.bmp"  ;11
#include "/images/alphabet/fg.bmp"  ;12
#include "/images/alphabet/hn.bmp"  ;13
#include "/images/alphabet/op_lowercase.bmp" ;14
#include "/images/alphabet/qr_lowercase.bmp" ;15
#include "/images/alphabet/ux.bmp"  ;16
#include "/images/alphabet/yz.bmp"  ;17
#include "/images/alphabet/23.bmp"  ;18
#include "/images/alphabet/45.bmp"  ;19
#include "/images/alphabet/67.bmp"  ;20
#include "/images/alphabet/89.bmp"  ;21
#include "/images/alphabet/MI.bmp"  ;22 start of 5x3
#include "/images/alphabet/VL.bmp"  ;23
#include "/images/alphabet/WT.bmp"  ;24
#include "/images/alphabet/mi_lowercase.bmp" ;25
#include "/images/alphabet/vl_lowercase.bmp" ;26
#include "/images/alphabet/Nt.bmp"  ;27
#include "/images/alphabet/K1.bmp"  ;28
#include "/images/alphabet/wj.bmp"  ;29
#include "/images/alphabet/dollarsign_questionmark.bmp"         ;30
#include "/images/alphabet/buttonbox.bmp" ;31
#include "/images/alphabet/period_comma_exclamationmark_s.bmp"  ;32 2x2x2x2
#include "/images/alphabet/colon_semicolon_leftparenthesis_rightparenthesis.bmp" ;33
#include "/images/alphabet/quote_hyphen_apostrophe.bmp"         ;34 3x3x2
Offline
User avatar

NanoWar

Site Admin

Re: Overriding default ASCII values in strings?

Post28 November 2011, 14:55

Okay, I see your problem. You have the character sprites semi-shuffled in memory. So you have multiple options:
  • Create custom font definitions, so that e.g. _r assembles into the correct sprite pointer of the letter 'r' :(
  • Remap the existing font definitions, using a look up table (LUT) that has the right offsets to the correct sprites :)
Code: Select all
font_lut_ABCD:
 .db 0, 4 ; 0 = offset; 4 = character width
 .db 4, 4
 .db 8, 4
 .db 12, 4
; ...

text:
 .db "ABCD", 0 ; = 41h, 42h, 43h, 44h, 00h

print
      ld    hl, text
print.loop
      ld    a, (hl)
      inc   hl
      or    a
      ret   z
      push  hl
            sub   'A' ; 41h
            ; TODO: detect lowercase here (when cp 'a' does not carry...)
            add   a, a ; *2 ; 2 bytes LUT entry size
            ld    b, 0
            ld    c, a
            ld    hl, font_lut_ABCD
            add   hl, bc
            ld    a, (hl)
            sra   a
            sra   a
            sra   a ; /8
            ld    c, a
            add   a, a ; *2
            add   a, c ; *3
            add   a, a ; *6 ; character height
            ld    c, a
            ; c = byte offset
            ld    a, (hl)
            and   %11111000 ; mod 8
            ; a = bit offset
            ld    b, 0
            ld    ix, font_sprites
            add   ix, bc
            inc   hl
            ld    b, (hl)
            ; a = bit offset
            ; b = character width
            ; ix = character sprite pointer
            call  display_character
      pop   hl
      jr    print.loop
??? Profit!!!
Attachments
6x4_8bit_width-map.bmp
Font Sprites
6x4_8bit_width-map.bmp (422 Bytes) Viewed 5609 times

Return to SPASM

Who is online

Users browsing this forum: No registered users and 1 guest

cron