'===========================================================================
' Subject: CAPTURE SCREEN & OUTPUT TO ASM     Date: 08-07-97 (00:16)       
'  Author: Benjamin L. McGee                  Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: ASMCODE.ABC
'===========================================================================
TYPE PointType
  Row AS INTEGER
  Col AS INTEGER
END TYPE

DECLARE SUB SetScreenArea (UpperLeft AS ANY, LowerRight AS ANY)
DECLARE SUB Screen2ASM (FileName$, ProcName$, UpperLeft AS PointType, LowerRight AS PointType)

' insert your screen drawing commands below
' sorry, this if for SREEN 0 ONLY!
 
SCREEN 0
CLS
 
FOR Count% = 1 TO 500
  PRINT "Hello World!";
NEXT Count%
 
DIM SHARED UpperLeft AS PointType
DIM SHARED LowerRight AS PointType
 
CALL SetScreenArea(UpperLeft, LowerRight)
CALL Screen2ASM("TEST.ASM", "TestScreen", UpperLeft, LowerRight)

'SCREEN.BAS
'DECLARE SUB TestScreen ()
'CALL TestScreen
'END

' split line
SUB Screen2ASM (FileName$, ProcName$, UpperLeft AS PointType, LowerRight AS PointType)
 
OutFile% = FREEFILE
 
OPEN FileName$ FOR OUTPUT AS OutFile%
 
PRINT #OutFile%, "; " + FileName$
PRINT #OutFile%, "; DECLARE SUB " + ProcName$ + " ()"
PRINT #OutFile%, "; " + TIME$
PRINT #OutFile%, "; " + DATE$
PRINT #OutFile%, "; assembles with the Arrowsoft Public Domain Assembler"
PRINT #OutFile%,
PRINT #OutFile%, "_BSS segment word public 'BSS'"
PRINT #OutFile%, "    ; not really necessary"
PRINT #OutFile%, "_BSS ends"
PRINT #OutFile%,
PRINT #OutFile%, "CONST segment word public 'DATA'"
PRINT #OutFile%, "    ; not really necessary"
PRINT #OutFile%, "CONST ends"
PRINT #OutFile%,
PRINT #OutFile%, "SCREEN_TEXT segment word public 'CODE'"
PRINT #OutFile%, "    DGROUP group CONST, _BSS"
PRINT #OutFile%, "    assume cs:SCREEN_TEXT, ds:DGROUP"
PRINT #OutFile%,
PRINT #OutFile%, ProcName$ + " proc far"
PRINT #OutFile%, "    public " + ProcName$
PRINT #OutFile%,
PRINT #OutFile%, "    push ds"
PRINT #OutFile%, "    mov ax, 0B800h"
PRINT #OutFile%, "    mov ds, ax"
PRINT #OutFile%,
 
DEF SEG = &HB800
 
FOR Row% = (UpperLeft.Row - 1) TO (LowerRight.Row - 1)
  PRINT #OutFile%,
  PRINT #OutFile%, ";   Row " + STR$(Row% + 1)
 
  StartOffset% = (Row% * 160) + ((UpperLeft.Col - 1) * 2)
  EndOffset% = StartOffset% + ((LowerRight.Col - UpperLeft.Col) * 2)
 
  FOR Offset% = StartOffset% TO EndOffset%
    PRINT #OutFile%, "    mov word ptr ds:[0";
    Offset$ = HEX$(Offset%)
    PRINT #OutFile%, Offset$ + "h], 0";
 
    Attribute% = PEEK(Offset%)
    Attribute$ = HEX$(Attribute%)
    IF LEN(Attribute$) < 2 THEN Attribute$ = "0" + Attribute$
    Offset% = Offset% + 1
    Character% = PEEK(Offset%)
    Character$ = HEX$(Character%)
 
    PRINT #OutFile%, Character$ + Attribute$ + "h"
  NEXT Offset%
 
NEXT Row%
 
DEF SEG
 
PRINT #OutFile%,
PRINT #OutFile%, "    pop ds"
PRINT #OutFile%, "    ret"
PRINT #OutFile%, ProcName$ + " endp"
PRINT #OutFile%, "SCREEN_TEXT ends"
PRINT #OutFile%, "end"
PRINT #OutFile%,
 
CLOSE OutFile%
 
END SUB

SUB SetScreenArea (UpperLeft AS PointType, LowerRight AS PointType)
 
Row% = 1
Col% = 1
 
DO
  IF Row% > 25 THEN Row% = 25
  IF Row% < 1 THEN Row% = 1
  IF Col% > 80 THEN Col% = 80
  IF Col% < 1 THEN Col% = 1
 
  LOCATE Row%, Col%, 1
  SELECT CASE INKEY$
    CASE CHR$(0) + CHR$(72)   ' up arrow
      Row% = Row% - 1
    CASE CHR$(0) + CHR$(80)   ' down arrow
      Row% = Row% + 1
    CASE CHR$(0) + CHR$(75)   ' left arrow
      Col% = Col% - 1
    CASE CHR$(0) + CHR$(77)   ' right arrow
      Col% = Col% + 1
    CASE CHR$(13)
      CR% = CR% + 1
      IF CR% = 1 THEN
        UpperLeft.Col = Col%
        UpperLeft.Row = Row%
      ELSE
      IF CR% = 2 THEN
        LowerRight.Col = Col%
        LowerRight.Row = Row%
      END IF
      END IF
  END SELECT
LOOP UNTIL CR% >= 2
 
END SUB
