Author Topic: redifine character set... something like on commodore64 or pcg on microbee  (Read 10148 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
I can make my own character set using pset, but how can i change the defaults to print using _printstring (x,y),my character so i can keep the speed and work with the system how it is

on microbee you just poke into a memory address and type pcg (user defined) and use the normal print commands
same as for commodore64, ti, sega, bbc so how can i do this. 8x8, 8x16, 16x16.
MackyWhite

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
You could make your own "print" character sub.

Setup character draw subs that use pset or lines or circles or ... that fit into a character block 8x16.

sub printChar x, y, charID
select case charID
case c1& : drawC1 x, y
case c2& : drawC2 x, y
...
end select
end sub

sub drawC1 x, y
pset (? + x, ? + y), color?
line ( ? + x, ? + y)-step(?, ?), color?
circle(? + x, ? + y), r, color?
... a bunch of drawing instructions to make the character, all offset by the x, y place to put the top left corner of block.
end sub

with such you can control the colors more than you could with with a font character. You can even make the characters scalable.
This is like making your own tiles.
« Last Edit: August 27, 2018, 09:30:00 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
You can also draw all the characters in advance into image handles and use _putimage where you want the character.
« Last Edit: August 27, 2018, 09:37:50 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Code: QB64: [Select]
  1. DIM SHARED chars(255) AS LONG
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.  
  4. FOR Ascii = 0 TO 255
  5.     chars(Ascii) = _NEWIMAGE(10, 20, 32)
  6.     _DEST chars(Ascii)
  7.     _PRINTSTRING (0, 0), CHR$(Ascii), chars(Ascii)
  8. NEXT Ascii
  9.  
  10. Prnt "What you think? Something this?", 1, 10, 10, 20, 15
  11. Prnt "You have many options in QB64...", 2, 10, 500, 20, -15
  12.  
  13.  
  14.  
  15. SUB Prnt (text AS STRING, size AS INTEGER, StartX AS INTEGER, StartY AS INTEGER, Xspace AS INTEGER, Yspace AS INTEGER)
  16.     x = StartX
  17.     y = StartY
  18.     FOR f = 1 TO LEN(text)
  19.         ch = ASC(text, f)
  20.         x = x + Xspace
  21.         IF x MOD 5 = 0 THEN y = y + Yspace
  22.         _PUTIMAGE (x, y)-(x + (size * 16), y + (size * (8 * f))), chars(ch), 0
  23.         _DELAY .1
  24.     NEXT
  25.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Or see here https://www.qb64.org/forum/index.php?topic=311.msg2031#msg2031. You can use _LoadFont and _Font before save points to array, then this point you can view as quads or circles or 3D objects....

Marked as best answer by PMACKAY on August 27, 2018, 10:06:47 am

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
I would use something like Davey W Taylor's Font Editor to make a new BIOS font and then load that. Galleon set me up a way to  get it to load in QB64. Just put the Charset.h in the QB64 directory.

DECLARE LIBRARY "charset"
 SUB Charset_8x8 (BYVAL o AS _OFFSET)
 SUB Charset_8x16 (BYVAL o AS _OFFSET)
END DECLARE
DIM SHARED c16(7, 15, 255) AS _UNSIGNED _BYTE, charload AS _UNSIGNED _BYTE

Code: QB64: [Select]
  1. CONST TRUE = -1, FALSE = NOT TRUE
  2. SUB loadreapingfont
  3.  OPEN "reaping.fnt" FOR BINARY AS #1
  4.  FOR c% = 0 TO 255
  5.   FOR y% = 0 TO 15
  6.    GET #1, , charload
  7.    FOR x% = 0 TO 7 'STEP -1
  8.     IF readbit(x%, charload) THEN c16(7 - x%, y%, c%) = 1 'any non-0 value should work
  9.    NEXT
  10.   NEXT
  11.  
  12. FUNCTION readbit (bit%, value%)
  13.  IF value% AND 2 ^ bit% THEN readbit = TRUE ELSE readbit = FALSE
  14.  

And I still use a POKE routine to display the text on screen 0 anyway. But that 'should' still work with normal PRINT or _PRINTSTRING in other screen modes as a 8x16 font. I think it will work with a 8x8 too but thats stuck on .NETs forum and until Galleon gets a backup copy to us to have here it maybe lost. Since I only use 8x16 I cut out the code for the 8x8 and don't have a copy.

Granted after becoming radioactive I only have a half-life!

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
I would use something like Davey W Taylor's Font Editor to make a new BIOS font and then load that. Galleon set me up a way to  get it to load in QB64. Just put the Charset.h in the QB64 directory.

DECLARE LIBRARY "charset"
 SUB Charset_8x8 (BYVAL o AS _OFFSET)
 SUB Charset_8x16 (BYVAL o AS _OFFSET)
END DECLARE
DIM SHARED c16(7, 15, 255) AS _UNSIGNED _BYTE, charload AS _UNSIGNED _BYTE

Code: QB64: [Select]
  1. CONST TRUE = -1, FALSE = NOT TRUE
  2. SUB loadreapingfont
  3.  OPEN "reaping.fnt" FOR BINARY AS #1
  4.  FOR c% = 0 TO 255
  5.   FOR y% = 0 TO 15
  6.    GET #1, , charload
  7.    FOR x% = 0 TO 7 'STEP -1
  8.     IF readbit(x%, charload) THEN c16(7 - x%, y%, c%) = 1 'any non-0 value should work
  9.    NEXT
  10.   NEXT
  11.  
  12. FUNCTION readbit (bit%, value%)
  13.  IF value% AND 2 ^ bit% THEN readbit = TRUE ELSE readbit = FALSE
  14.  

And I still use a POKE routine to display the text on screen 0 anyway. But that 'should' still work with normal PRINT or _PRINTSTRING in other screen modes as a 8x16 font. I think it will work with a 8x8 too but thats stuck on .NETs forum and until Galleon gets a backup copy to us to have here it maybe lost. Since I only use 8x16 I cut out the code for the 8x8 and don't have a copy.
thank you. this is what was looking for. as for 8 x 8 i can just double the length anyway :) cheers
MackyWhite

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
thank you guys for the kind help.... :) I will jump straight to it... when i wake up    3:12am here in australia. ZZZzzzZZzzZ   me
MackyWhite

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Melbourne. Where are you?

J
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
I used to have an Amstrad (8bit) back in the mid to late 80's and it, like the commodore and others, could redefine characters. I think they were re definable for two reasons. 1. If you had a LOT of patience - a new character set and 2. To create 8x8 tiles. I think the idea is, it is quicker to display a 64 pixel 'text' tile than it is to plot a 64 pixel tile. After all, a 4 mhz cpu, can only do SO much... lol

The method of 'mapping' the characters was using pencil and paper... Not as easy as THIS program. Great Job! Ah the memories...

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Ascii Character Editor sounded interesting, here is what I came up with today:
Code: QB64: [Select]
  1. _TITLE "Ascii Character Editor"
  2. 'started 2018-08-27 by bplus
  3. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  4.  
  5. '========================== Instructions: =================================
  6. '
  7. ' Arrow keys move the highlighter around, spacebar toggles tile on/off
  8. ' or just click with mouse to do the same.
  9.  
  10. ' Click buttons to either
  11. ' 1. Enter an ascii by number to edit.
  12. ' 2. Enter a character by pressing the key(s) from which the anscii number is taken.
  13. ' 3. Save a modified character.
  14. ' 4. Save all edits made to flie called "Character Set.DAT".
  15. ' Note: If want to work with more sets, just rename Character Set.DAT
  16. '       If that file isn't found, this app will start from scratch.
  17. '
  18. '==========================================================================
  19.  
  20. CONST CW = 8
  21. CONST CH = 16
  22. CONST SQ = 25
  23. CONST XOFF = 60
  24. CONST YOFF = 80
  25. CONST WW = 800
  26. CONST WH = 600
  27. SCREEN _NEWIMAGE(WW, WH, 32)
  28. _SCREENMOVE (1280 - WW) / 2 + 30, (760 - WH) / 2
  29. DIM SHARED AN%, CX, CY, BLK AS _UNSIGNED LONG, WHT AS _UNSIGNED LONG, FILE$
  30. DIM SHARED MAP(CW + 2, CH + 2) AS STRING * 1
  31. DIM SHARED CS(256) AS STRING * 128
  32. WHT = _RGB32(255, 255, 255)
  33. BLK = _RGB32(0, 0, 0)
  34.  
  35. '==============================   main
  36.  
  37. 'see if there is a file in the works to load else start from scratch
  38. IF _FILEEXISTS("Character Set.DAT") THEN
  39.     OPEN "Character Set.DAT" FOR INPUT AS #1
  40.     FOR i = 1 TO 256
  41.         INPUT #1, CS(i - 1)
  42.     NEXT
  43.     CLOSE #1
  44.     FILE$ = "Character Set.DAT"
  45.     FOR a = 0 TO 255
  46.         CLS
  47.         _PRINTSTRING (0, 0), CHR$(a)
  48.         b$ = ""
  49.         FOR y = 0 TO CH - 1
  50.             FOR x = 0 TO CW - 1
  51.                 IF POINT(x, y) <> BLK THEN b$ = b$ + "1" ELSE b$ = b$ + "0"
  52.             NEXT
  53.         NEXT
  54.         CS(a) = b$
  55.     NEXT
  56.     FILE$ = "Nothing saved yet."
  57.  
  58. FOR i = 1 TO 128
  59.     PRINT MID$(CS(1), i, 1);
  60.     IF i MOD CW = 0 THEN PRINT
  61. 'END
  62. 'sample B for starters
  63. AN% = 66
  64. load AN%
  65. CX = 1: CY = 1
  66.         mx = _MOUSEX
  67.         my = _MOUSEY
  68.         _DELAY .2
  69.         'ascii #  to edit
  70.         IF mx > 500 AND mx < 700 AND my > 50 AND my < 100 THEN
  71.             COLOR WHT, 0
  72.             LINE (500, 50)-(700, 100), BLK, BF
  73.             LOCATE 5, 67: INPUT "Ascii # "; a%
  74.             IF a% >= 0 AND a% <= 255 THEN AN% = a%: load AN%
  75.         END IF
  76.         'chr$  to edit
  77.         IF mx > 500 AND mx < 700 AND my > 110 AND my < 160 THEN
  78.             COLOR WHT, 0
  79.             LINE (500, 110)-(700, 160), BLK, BF
  80.             LOCATE 9, 67: INPUT "Enter Chr$ "; char$
  81.             a% = ASC(char$)
  82.             IF a% >= 0 AND a% <= 255 THEN AN% = a%: load AN%
  83.         END IF
  84.         'save character edit
  85.         IF mx > 500 AND mx < 700 AND my > 170 AND my < 220 THEN
  86.             b$ = ""
  87.             FOR y = 1 TO CH
  88.                 FOR x = 1 TO CW
  89.                     b$ = b$ + MAP(x, y)
  90.                 NEXT
  91.             NEXT
  92.             CS(AN%) = b$
  93.             COLOR WHT, 0
  94.             LINE (500, 170)-(700, 220), BLK, BF
  95.             LOCATE 13, 67: PRINT " Character recorded. "
  96.             _DISPLAY
  97.             _DELAY 1.5
  98.         END IF
  99.         'file character set
  100.         IF mx > 500 AND mx < 700 AND my > 230 AND my < 280 THEN
  101.             COLOR WHT, 0
  102.             LINE (500, 230)-(700, 280), BLK, BF
  103.             OPEN "Character Set.DAT" FOR OUTPUT AS #1
  104.             FOR a = 0 TO 255
  105.                 PRINT #1, CS(a)
  106.             NEXT
  107.             CLOSE #1
  108.             LOCATE 16, 65: PRINT "Filed Character Set.DAT"
  109.             _DISPLAY
  110.             _DELAY 1.5
  111.         END IF
  112.  
  113.         'mouse over edit box, toggle tiles and update cursor
  114.         tx = (mx - XOFF) \ SQ: ty = (my - YOFF) \ SQ
  115.         IF tx >= 1 AND tx <= CW AND ty >= 1 AND ty <= CH THEN
  116.             CX = tx: CY = ty
  117.             IF MAP(CX, CY) = "1" THEN MAP(CX, CY) = "0" ELSE MAP(CX, CY) = "1"
  118.         END IF
  119.     END IF
  120.     KH& = _KEYHIT
  121.     SELECT CASE KH&
  122.         CASE 32 'space bar
  123.             IF MAP(CX, CY) = "1" THEN MAP(CX, CY) = "0" ELSE MAP(CX, CY) = "1"
  124.         CASE 18432 'up
  125.             IF CY - 1 >= 1 THEN CY = CY - 1
  126.         CASE 20480 'down
  127.             IF CY + 1 <= CH THEN CY = CY + 1
  128.         CASE 19200 'left
  129.             IF CX - 1 >= 1 THEN CX = CX - 1
  130.         CASE 19712 'right
  131.             IF CX + 1 <= CW THEN CX = CX + 1
  132.     END SELECT
  133.  
  134.     IF _KEYDOWN(27) THEN END
  135.     update
  136.     _DISPLAY
  137.     _LIMIT 60
  138.  
  139. SUB load (asci)
  140.     FOR i = 1 TO 128
  141.         y = i \ CW + 1
  142.         x = i MOD CW: IF x = 0 THEN x = 8: y = y - 1
  143.         MAP(x, y) = MID$(CS(asci), i, 1)
  144.     NEXT
  145.  
  146. SUB update
  147.     COLOR WHT, _RGB32(100, 110, 100): CLS
  148.     drwBtn 500, 50, "Load map with Ascii"
  149.     drwBtn 500, 110, "Load map with Chr$"
  150.     drwBtn 500, 170, "Save Character Edit"
  151.     drwBtn 500, 230, "File Character Set"
  152.     COLOR _RGB32(250, 225, 255), _RGB32(100, 110, 100)
  153.     _PRINTSTRING (398, 400), "Current Ascii% =" + STR$(AN%) + " or CHR$(" + LTRIM$(STR$(AN%)) + ") = " + CHR$(AN%)
  154.     _PRINTSTRING (398, 440), "File: " + FILE$
  155.     LINE (XOFF - 1, YOFF - 1)-STEP((CW + 2) * SQ + 2, (CH + 2) * SQ + 2), _RGB32(255, 255, 0), B
  156.     LINE (XOFF + 1, YOFF + 1)-STEP((CW + 2) * SQ, (CH + 2) * SQ), BLK, B
  157.     LINE (XOFF, YOFF)-STEP((CW + 2) * SQ, (CH + 2) * SQ), _RGB32(255, 80, 0), BF
  158.     FOR y = 1 TO CH
  159.         FOR x = 1 TO CW
  160.             IF MAP(x, y) = "1" THEN c& = _RGB32(200, 200, 200) ELSE c& = _RGB32(0, 0, 0)
  161.             LINE ((x) * SQ + XOFF, (y) * SQ + YOFF)-STEP(SQ - 2, SQ - 2), c&, BF
  162.         NEXT
  163.     NEXT
  164.     ' let's see actual size!
  165.     COLOR _RGB32(255, 255, 0), _RGB32(100, 110, 100)
  166.     FOR i = 1 TO 4
  167.         drwChar XOFF + 16 * (i * 2), .5 * YOFF - (16 * i) / 2, AN%, i
  168.     NEXT
  169.     'highlight sqr
  170.     LINE (CX * SQ - 1 + XOFF, CY * SQ - 1 + YOFF)-STEP(SQ, SQ), WHT, B
  171.  
  172.  
  173. SUB drwBtn (x, y, s$)
  174.     th = 16: tw = 8 * LEN(s$): gray& = _RGB32(190, 190, 190)
  175.     LINE (x, y)-STEP(200, 50), _RGB32(0, 0, 0), BF
  176.     LINE (x, y)-STEP(197, 47), _RGB32(255, 255, 255), BF
  177.     LINE (x + 1, y + 1)-STEP(197, 47), gray&, BF
  178.     COLOR _RGB32(0, 0, 0), gray&
  179.     _PRINTSTRING (x + 100 - 4 * LEN(s$), y + 17), s$
  180.  
  181. SUB drwChar (x0, y0, ascn, size) 'what ever the present color is set at
  182.     FOR y = 0 TO CH - 1
  183.         FOR x = 0 TO CW - 1
  184.             i = i + 1
  185.             IF MID$(CS(ascn), i, 1) = "1" THEN LINE (x0 + x * size, y0 + y * size)-STEP(size - 1, size - 1), , BF
  186.         NEXT
  187.     NEXT
  188.  
 [ You are not allowed to view this attachment ]  

Then a quick little demo, showing table:
Code: QB64: [Select]
  1. _TITLE "Using custom characters"
  2. 'started 2018-08-27 by bplus
  3. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  4.  
  5.  
  6. CONST CW = 8
  7. CONST CH = 16
  8. CONST WW = 800
  9. CONST WH = 600
  10. CONST MAPW = 30
  11. CONST MAPH = 20
  12. CONST sq = 20
  13. SCREEN _NEWIMAGE(WW, WH, 32)
  14. _SCREENMOVE (1280 - WW) / 2 + 30, (760 - WH) / 2
  15. DIM SHARED AN%, CX, CY, BLK AS _UNSIGNED LONG, WHT AS _UNSIGNED LONG, FILE$
  16. DIM SHARED MAP(CW + 2, CH + 2) AS STRING * 1
  17. DIM SHARED CS(256) AS STRING * 128
  18. WHT = _RGB32(255, 255, 255)
  19. BLK = _RGB32(0, 0, 0)
  20.  
  21. '==============================   main
  22.  
  23. i = 0
  24. FOR y = 10 TO 500 STEP 40
  25.     FOR x = 10 TO 700 STEP 40
  26.         drwChar x, y, i, 2
  27.         i = i + 1
  28.         IF i > 155 THEN END
  29.     NEXT
  30.  
  31. SUB drwChar (x0, y0, ascn, size) 'what ever the present color is set at
  32.     'CS() DIM SHARED in starting setup
  33.     STATIC beenHere
  34.     IF beenHere = 0 THEN
  35.         'see if there is a file in the works to load else start from scratch
  36.         IF _FILEEXISTS("Character Set.DAT") THEN
  37.             OPEN "Character Set.DAT" FOR INPUT AS #1
  38.             FOR i = 1 TO 256
  39.                 INPUT #1, CS(i - 1)
  40.             NEXT
  41.             CLOSE #1
  42.             FILE$ = "Character Set.DAT"
  43.         ELSE
  44.             PRINT "Can't find Character Set.DAT file, goodbye!"
  45.             END
  46.         END IF
  47.         beenHere = -1
  48.     END IF
  49.     FOR y = 0 TO CH - 1
  50.         FOR x = 0 TO CW - 1
  51.             i = i + 1
  52.             IF MID$(CS(ascn), i, 1) = "1" THEN LINE (x0 + x * size, y0 + y * size)-STEP(size - 1, size - 1), , BF
  53.         NEXT
  54.     NEXT
  55.  
 [ You are not allowed to view this attachment ]  

FellippeHeitor

  • Guest
Now that was quick, bplus! And it does look good too!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Just curious. Why are the characters 8x16? The old characters were 8x8...

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
I was using QB64 default font. BTW, these characters can't be printed in normal PRINT statement, they are copied so all original characters remain intact and you make your own print statements by stringing the 8x16 tiles together or resize them and draw bigger!

If QB64 is not fast enough (it usually is), draw the characters to image handles as Petr has shown and make your own _printstring sub.
« Last Edit: August 28, 2018, 08:56:51 am by bplus »

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
I used to have an Amstrad (8bit) back in the mid to late 80's and it, like the commodore and others, could redefine characters. I think they were re definable for two reasons. 1. If you had a LOT of patience - a new character set and 2. To create 8x8 tiles. I think the idea is, it is quicker to display a 64 pixel 'text' tile than it is to plot a 64 pixel tile. After all, a 4 mhz cpu, can only do SO much... lol

The method of 'mapping' the characters was using pencil and paper... Not as easy as THIS program. Great Job! Ah the memories...

J

this is what i want, not to make a new sub or thing, just straight out replacement of the character. redifine it.... the routine is faster to just print rather then slow the computer down using pset (x,y): i am able to rip character roms from original roms, but i just want to change a few not the whole set. its really to make my game more appealing... a monster as a monster. brick as bricks and so on. the ascii is great but now i want to be more creative.
MackyWhite