*
*``````````````````````````````*
* DEMO.LORES                   *
*                              *
* A DEMO OF THE MACROS AND     *
* SUBROUTINES FOR USING LORES  *
* GRAPHICS.                    *
*                              *
* AUTHOR:    NATHAN RIGGS      *
* CONTACT:   NATHAN.RIGGS@     *
*            OUTLOOK.COM       *
*                              *
* DATE:      03-OCT-2019       *
* ASSEMBLER: MERLIN 8 PRO      *
* OS:        DOS 3.3           *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** ASSEMBLER DIRECTIVES
*
         CYC   AVE
         EXP   OFF
         TR    ON
         DSK   DEMO.HIRES
         OBJ   $BFE0
         ORG   $6000
*
*``````````````````````````````*
*  TOP INCLUDES (PUTS, MACROS) *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
         PUT   MIN.HEAD.REQUIRED.ASM
         PUT   MIN.HEAD.HIRES.ASM
         USE   MIN.MAC.REQUIRED.ASM
         USE   MIN.MAC.HIRES.ASM
*
*``````````````````````````````*
*      PROGRAM MAIN BODY       *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
         BIT   HPAGE1
         HCLR  #HBLACK1
         BIT   HMIXOFF
         BIT   HIRES
         BIT   GRAPHICS
*
*``````````````````````````````*
* HIRES CHARACTERS             *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE HIRES COLLECTION PROVIDES TWO WAYS TO PLOT
** CHARACTERS TO THE SCREEN: HCHAR AND HSTR. HCHAR
** PLOTS A SINGLE CHARACTER, WHILE HSTR PLOTS AN
** ENTIRE STRING TO THE WORKING HIRES PAGE.
*
** GENERALLY, HCHAR SHOULD BE AVOIDED AS IT WILL
** QUICKLY EAT UP AVAILABLE MEMORY IF USED EXTENSIVELY.
** EVEN WHEN PLOTTING A SINGLE CHARACTER, HRSTR IS
** USUALLY MORE APPROPRIATE UNLESS SPEED IS A CONCERN.
*
** HCHAR TAKES AN X-POSITION OF THE BYTE (0..39), A
** PIXEL Y-POSITION (0..191) AND THE BYTE TO PLOT TO
** THE SCREEN. NOTE THAT BECAUSE COLORS ARE DETERMINED
** BY SCREEN POSITION, THERE IS NO OPTION FOR CHANGING
** THE COLOR OF THE TEXT. THE CHARACTER TABLE IS BUILT
** WITH THE ASSUMPTION THAT THE TEXT WILL BE WHITE, AS
** EACH CHARACTER DOUBLES UP ON ADJACENT PIXELS AS MUCH
** AS POSSIBLE TO AVOID ACCIDENTAL TINTS (THIS IS UNAVOIDABLE
** IN THE LONG RUN, HOWEVER).
*
** THE HSTR MACRO SIMILARLY TAKES AN X AND Y POSITION WITH
** THE CHARACTER TO BE PLOTTED. ADDITIONALLY, THIS MACRO
** ACCEPTS A CHANGEABLE OFFSET FOR DIFFERENT ASCII TABLE
** CONFIGURATIONS ON DIFFERENT MACHINES. AS A BONUS, IT IS
** ALSO POSSIBLE TO SET THE OFFSET SO THAT EVEN IF A MACHINE
** DOES NOT HAVE LOWERCASE LETTERS, THEY CAN BE PLOTTED TO
** THE HIRES SCREEN.
*
         HCHAR #20;#160;HRT_T
         HCHAR #21;#160;HRT_E
         HCHAR #22;#160;HRT_S
         HCHAR #23;#160;HRT_T
*
         HSTR  #0;#0;#STR0;#IIESET
         HSTR  #0;#16;#STR1;#IIESET
         HSTR  #0;#24;#STR2;#IIESET
         HSTR  #0;#32;#STR3;#IIESET
         HSTR  #0;#40;#STR4;#IIESET
         HSTR  #0;#48;#STR5;#LOWSET
*
*``````````````````````````````*
* FILLING THE SCREEN           *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE HCLR MACRO FILLS THE SCREEN WITH THE COLOR
** SPECIFIED BY THE GIVEN COLOR CODE.
*
         _WAIT
         HCLR  #0
         _WAIT
         HCLR  #1
         _WAIT
         HCLR  #2
         _WAIT
         HCLR  #3
         _WAIT
         HCLR  #4
         _WAIT
         HCLR  #5
         _WAIT
         HCLR  #6
         _WAIT
         HCLR  #7
         _WAIT
         HCLR  #HBLACK1
*
*``````````````````````````````*
* HIRES PIXEL PLOTTING         *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE HPLOT MACRO PLOTS A PIXEL AT A GIVE X,Y COORDINATE
** IN THE SPECIFIED COLOR TO THE WORKING HIRES PAGE (SEE
** BELOW). NOTE THAT BECAUSE OF THE WAY THAT THE APPLE II
** ORGANIZES THE HIRES MEMORY PAGE, THIS IS ACTUALLY MUCH
** SLOWER THAN PLOTTING ENTIRE BYTES (SEE BELOW).
*
** CURRENTLY, THE PLOTTING SUBROUTINE IS NOT OPTIMIZED.
** THIS MAKES IT EASIER TO UNDERSTAND, BUT ALSO CAUSES
** THE PLOTTING SUBROUTINE TO BE SLIGHTLY SLOWER THAN THE
** EQUIVALENT APPLESOFT SUBROUTINE, EVEN USING TABLE LOOKUPS.
** THIS WILL BE ADDRESSED IN FUTURE UPDATES.
*
         HPLOT #160;#95;#HWHITE1
         HPLOT #161;#96;#HWHITE1
         HPLOT #162;#97;#HWHITE1
         HPLOT #162;#98;#HWHITE1
         _WAIT
*
*``````````````````````````````*
* HORIZONTAL LINES             *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE HLIN MACRO DRAWS A HORIZONTAL LINE TO THE
** WORKING HIRES PAGE STARTING AT AN X ORIGIN AND
** CONTINUING TO AN X DESTINATION AT THE GIVEN
** Y COORDINATE AND COLOR.
*
         LDY   #255
         STY   COUNTER
LP
         INC   COUNTER
         HLIN #10;#050;COUNTER;#HBLUE
         LDY   COUNTER
         CPY   #191
         BNE   LP
*
*``````````````````````````````*
* VERTICAL LINES               *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE VLIN MACRO CREATES A VERTICAL LINE AT THE
** GIVEN X AXIS STARTING AT A Y ORIGIN AND ENDING
** AT A Y DESTINATION (IN THE PROVIDED COLOR).
*
         VLIN  #10;#100;#20;#HGREEN
         VLIN  #10;#100;#21;#HGREEN
         VLIN  #10;#100;#100;#HGREEN
         VLIN  #10;#100;#101;#HGREEN
         VLIN  #10;#100;#102;#HGREEN
         VLIN  #10;#100;#103;#HGREEN
         VLIN  #10;#100;#104;#HGREEN
         VLIN  #10;#100;#105;#HGREEN
         VLIN  #10;#100;#106;#HGREEN
         VLIN  #10;#100;#107;#HGREEN
*
** NOTE TWO THINGS HERE: FIRST, WHEN GREEN IS
** PLOTTED NEXT TO PURPLE, THE RESULTING COLOR IS
** WHITE: THIS IS INEVITABLE, AND REQUIRES FORETHOUGHT
** WHEN USING HIRES GRAPHICS. SECOND, IF YOU LOOK
** CLOSELY YOU CAN SEE THAT SOME GREEN LINES ARE NOT
** PLOTTED TO THE SCREEN. THIS, TOO, IS DUE TO THE WAY
** THAT THE APPLE II DISPLAYS COLOR, AND IS UNAVOIDABLE.
*
*
*``````````````````````````````*
* ARBITRARY LINES              *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE LAST OF THE PIXEL-BY-PIXEL PLOTTING MACROS
** IS THE LINE MACRO, WHICH PLOTS A LINE FROM A
** GIVEN X0,Y0 STARTING POINT TO AN ENDING X1,Y1
** COORDINATE, IN THE COLOR SPECIFIED. NOTE THAT
** SINCE THIS USES THE PLOTTING ROUTINE, COLOR
** ISSUES ARE ALREADY TAKEN CARE OF; A BLUE LINE
** WILL ONLY PLOT TO BLUE PIXELS, GREEN TO GREEN,
** ETC. HOWEVER, THIS DOES HAVE THE POTENTIAL TO
** CHANGE THE HIGH BIT OF A BYTE IN SCREEN MEMORY
** THAT WILL RESULT IN CHANGING THE COLOR OF NEARBY
** PIXELS. THIS IS AGAIN UNAVOIDABLE, AND CARE HAS
** TO BE TAKEN BY THE USER TO ONLY PLOT LINES WHERE
** THE HIGH BYTES MATCH.
*
         LINE  #01;#01;#200;#048;#HBLUE
         LINE  #200;#1;#250;#100;#HPURPLE
         LINE  #10;#10;#200;#150;#HORANGE
         _WAIT
*
** NOTE THAT CURRENTLY, THE LINE ALGORITHM IS
** EQUIPPED ONLY TO GO FROM LOWER VALUES TO
** HIGHER VALUES, ON BOTH X AND Y AXES. THIS WILL
** BE FIXED IN A FUTURE UPDATE.
*
*``````````````````````````````*
* PLOTTING BYTES TO THE SCREEN *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THE HBSET MACRO PLOTS AN ENTIRE BYTE TO
** SCREEN MEMORY. THIS CAN BE USED FOR QUICKLY
** DISPLAYING TILES (LIKE THE HIRES CHARACTERS)
** ON THE SCREEN. NOTE THAT SINCE COLOR IS
** DETERMINED BY SCREEN POSITION, THE VALUE OF
** THE BYTE DETERMINES THE COLORS OF THE INDIVIDUAL
** PIXELS. THIS IS FURTHER CONFOUNDED BY THE FACT
** THAT EVEN AND ODD COLUMNS OF BYTES REVERSE WHICH
** COLOR IS PLOTTED BASED ON POSITION, SO CARE MUST
** BE TAKEN WELL AHEAD OF TIME TO GUARANTEE THE CORRECT
** COLORS WILL BE DISPLAYED.
*
         HBSET #10;#100+0;TILE+0
         HBSET #10;#100+1;TILE+1
         HBSET #10;#100+2;TILE+2
         HBSET #10;#100+3;TILE+3
         HBSET #10;#100+4;TILE+4
         HBSET #10;#100+5;TILE+5
         HBSET #10;#100+6;TILE+6
         HBSET #10;#100+7;TILE+7
*
** IF YOU LOOK AT THE TILE DEFINITION AT THE
** BOTTOM OF THIS LISTING, YOU'LL SEE THAT A
** TILE IS 7 * 8 BITS WIDE AND LONG (THE HIGH
** BIT OF EACH BYTE IS USED FOR COLOR, AND IS
** NOT INCLUDED HERE; HOWEVER, IT CAN BE INCLUDED
** IF COLOR IS A CONCERN). THIS MEANS THAT EACH
** TILE CONSISTS OF 8 BYTES, TO BE PLOTTED IN THE
** ORDER ABOVE.
*
*``````````````````````````````*
* PAGE FLIPPING                *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** THERE ARE TWO PAGES FOR THE HIRES SCREEN THAT
** CAN BE PLOTTED TO OR VIEWED SEPERATELY. THIS IS
** MOSTLY USED TO CREATE SMOOTHER ANIMATIONS. THE
** MACROS USED TO HANDLE THIS ARE HVIEWPG AND
** HWORKPG, FOR SETTING THE PAGE TO CURRENTLY DISPLAY
** AND FOR SETTING THE PAGE TO PLOT TO, RESPECTIVELY.
*
********************************
*
** NOTE: THIS DOES NOT WORK IF YOU CURRENTLY HAVE
** MERLIN 8 PRO LOADED. TO SEE THIS IN EFFECT, YOU
** WILL HAVE TO BOOT FROM A CLEAN DOS DISK, THEN LOAD
** THIS DISK.
*
********************************
*
         HWORKPG #2       ; SET THE PLOTTING PAGE TO 2
                          ; WHILE THE VIEWING PAGE IS STILL
                          ; SET TO PAGE 1
*
         HCLR  #HBLACK1
         HSTR  #10;#10;"PAGE 2!";#IIESET
         HVIEWPG #2       ; DISPLAY PAGE 2
         _WAIT
         HVIEWPG #1       ; SET TO VIEW PAGE 1 AGAIN
         HWORKPG #1       ; ALSO PLOT TO PAGE 1 AGAIN
         _WAIT
*
         BIT   HTEXTM     ; SET TEXT MODE
         _PRN  " ",8D8D
         _PRN  "FIN!",8D8D
*
         JMP   $3D0
*
*``````````````````````````````*
*        BOTTOM INCLUDES       *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
** BOTTOM INCLUDES
*
         PUT   MIN.LIB.REQUIRED.ASM
*
** INDIVIDUAL SUBROUTINE INCLUDES
*
         PUT   MIN.SUB.HRPLOT.ASM
         PUT   MIN.SUB.HCLEAR.ASM
         PUT   MIN.SUB.HRHLINE.ASM
         PUT   MIN.SUB.HRVLINE.ASM
         PUT   MIN.SUB.HRBLINE.ASM
         PUT   MIN.SUB.HRSTR.ASM
         PUT   TBL.HRCHAR.ASM
         PUT   TBL.HIRES.ASM
         PUT   TBL.DB7.ASM
*
COUNTER  DS    1
STR0     STR   "WELCOME TO HIGH RESOLUTION!"
STR1     STR   " !#$%&'()*+,-./0123456789:;<=>?@"
STR2     HEX   01A2       ; THIS IS A " CHARACTER
STR3     STR   "ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`"
STR4     STR   "abcdefghijklmnopqrstuvwxyz{|}~"
STR5     STR   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
TILE     DB    %1111111
         DB    %1000001
         DB    %1010101
         DB    %1000001
         DB    %1010101
         DB    %1011101
         DB    %1000001
         DB    %1111111
