Qbasicnews.com

Full Version: ASM SCREEN 12 PSET routine...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I need a SCREEN 12 PSET routine written in assembly. I could translate that routine I posted in the FAQ, but I suck at assembly coding.

It would be cake if anyone could give me such routine usable from a CALL ABSOLUTE statement.
Unoptimized and untested:
Code:
;DECLARE SUB pix12 (BYVAL vertical%, BYVAL horizontal%, BYVAL c%)
public pix12
pix12 proc, vertical:sword, horizontal:sword, col:word

;   IF (vertical% < 0) OR (horizontal% < 0) THEN EXIT SUB
   .if vertical < 0 || horizontal < 0
      ret
   .endif

;   IF (vertical% > 479) OR (horizontal% > 639) THEN EXIT SUB
   .if vertical > 479 || horizontal > 639
      ret
   .endif

;   DEF SEG = &HA000
   mov  ax, 0A000h
   mov  es, ax

;   OUT &H3CE, 4: OUT &H3C4, 2
   mov  dx, 03CEh
   mov  al, 4
   out  dx, al
   mov  dl, 0C4h
   mov  al, 2
   out  dx, al

;   P& = vertical%: P& = P& * 80 + horizontal% \ 8
   mov  ax, vertical
   mov  di, ax
   shl  ax, 6  ; ax = vertical * 64
   shl  di, 4  ; di = vertical * 16
   add  di, ax ; di = vertical * 80
   mov  ax, horizontal
   shr  ax, 3
   add  di, ax

;   bit% = bitfield(horizontal% AND 7): bitmask% = 255 - bit%
   mov  cl, horizontal
   and  cl, 00000111b
   mov  bh, 10000000b
   shr  bh, cl
   mov  ch, bh
   not  ch

;   OUT &H3CF, 0: OUT &H3C5, 1
   mov  dx, 03CFh
   xor  al, al
   out  dx, al
   mov  dl, 0C5h
   inc  al
   out  dx, al

;   B% = PEEK(P&) AND bitmask%
   mov  al, es:[di]
   and  al, ch

;   IF (c% AND 1) <> 0 THEN B% = B% OR bit%
   mov  cl, byte ptr col
   .if cl & 0001b
      or   al, bh
   .endif

;   POKE P&, B%
   mov  es:[di], al

;   OUT &H3CF, 1: OUT &H3C5, 2
   mov  dx, 03CFh
   mov  al, 1
   out  dx, al
   mov  dl, 0C5h
   inc  al
   out  dx, al

;   B% = PEEK(P&) AND bitmask%
   mov  al, es:[di]
   and  al, ch

;   IF (c% AND 2) <> 0 THEN B% = B% OR bit%
   .if cl & 0010b
      or   al, bh
   .endif

;   POKE P&, B%
   mov  es:[di], al

;   OUT &H3CF, 2: OUT &H3C5, 4
   mov  dx, 03CFh
   mov  al, 2
   out  dx, al
   mov  dl, 0C5h
   mov  al, 4
   out  dx, al

;   B% = PEEK(P&) AND bitmask%
   mov  al, es:[di]
   and  al, ch

;   IF (c% AND 4) <> 0 THEN B% = B% OR bit%
   .if cl & 0100b
      or   al, bh
   .endif

;   POKE P&, B%
   mov  es:[di], al

;   OUT &H3CF, 3: OUT &H3C5, 8
   mov  dx, 03CFh
   mov  al, 3
   out  dx, al
   mov  dl, 0C5h
   mov  al, 8
   out  dx, al

;   B% = PEEK(P&) AND bitmask%
   mov  al, es:[di]
   and  al, ch

;   IF (c% AND 8) <> 0 THEN B% = B% OR bit%
   .if cl & 1000b
      or   al, bh
   .endif

;   POKE P&, B%
   mov  es:[di], al

;END SUB
   ret
pix12 endp
Wow, that asm code is just better in every way than mine. Oh well, I was bored and wanted something to do.
Ok, thanks both. Now I need some kind of tutorial about how to stuff that inside DATAs or whatever and make it "callable" with CALL ABSOLUTE. Any hints?

Sorry, but I have NO IDEA about how to pass values to a CALL ABSOLUTE function (like that x, y, c in the PASCAL code). I am fearing that I am gonna have to use a nice stack frame... Sad
Well, basically you just take out any masm/tasm stuff like .model, and run it through DEBUG, then OPEN the .com file, load to a string or whatever, and CALL ABSOLUTE the string.

Or you could just use one of those "qbasic assemblers" like QASM - they do it all for you. This is the way to go if you'd rather load the code from DATA statements instead of an external file.

Here's the code Plasma linked to, with the pascal stuff removed. I did the stack frame for you. You need to do each one in a separate file.

EDIT: that label in the point routine might be a problem, DEBUG probably won't like it. 2 ways to resolve that: the fun way and the easy way. Fun way: calculate the size in bytes of the instructions between the jump and the label so you can do it the way DEBUG likes it (it'll be JGE $-??, or something like that I think). The easy way: use a "qbasic assembler" most (if not all) of which take care of this for you.

EDIT #2: I just remembered, DEBUG takes numbers in hex by default... again your best option is to use something like QASM or whatever it's called.

EDIT #3: I found one. It's called Absolute Assembler. The site that has it for download is here, the file itself is here, but I think geocities doesn't allow outside linking.

EDIT #4: It doesn't look as if Absolute Assember accounts for the fact that DEBUG takes numbers in hex. I'll convert everthing to hex.

pset12.asm
Code:
PUSH BP
  MOV BP, SP
  MOV AX, 0A000
  MOV ES, AX
  MOV DI, [BP+0A]
  MOV CX, DI
  SHR DI, 3
  MOV AX, 50
  MUL [BP+8]
  ADD DI, AX
  AND CL, 07
  MOV AH, 80
  SHR AH, CL
  MOV AL, 08
  MOV DX, 03CE
  OUT DX, AX
  MOV AL, [BP+6]
  MOV AH, ES:[DI]
  MOV ES:[DI], AL
  POP BP
  RET 6

point12.asm
Code:
PUSH BP
  MOV BP, SP
  MOV  AX, 50
  MUL  [BP+6]
  MOV  SI, [BP+8]
  MOV  CX, SI
  SHR  SI, 3
  ADD  SI, AX
  AND  CL, 07
  XOR  CL, 07
  MOV  CH, 1
  SHL  CH, CL
  MOV  AX, 0A000
  MOV  ES, AX
  MOV  DX, 03CE
  MOV  AX, 304
  XOR  BL, BL
@gp1:
  OUT  DX, AX
  MOV  BH, ES:[SI]
  AND  BH, CH
  NEG  BH
  ROL  BX, 01
  DEC  AH
  JGE  @gp1
  XOR AH, AH
  MOV  AL, BL
  POP BP
  RET 4
Oh, man, thank you very much. I'll research on everything you've pointed out. That's great Smile

Thanks again.
You're welcome 8) . Let me know if it doesn't work.
Well. I've tried that Absolute Assembly program. It hangs up while "calculating code length". After 30 minutes, I CTRL+BREAKed and I realized that a strange 12-Megs temp file was created and it was full of CHR$(7) (bel) characters. Odd, isn't it?

But anyhow, this is a problem that I can work out. I will just peek in the Absolute Assembly code and I will try to do things by hand. Thank you for your support.
*gasp*

the godlike nathan asks for help???

*dun dun dun!*
Pages: 1 2 3