OPT D+,C+ * SET TABS TO 9!! * Initialize stuff: BSR START * A5 now points to the screen base. * Your code goes here: * Program to print 8 factorials. MOVEQ #0,D6 MOVEQ #1,D5 main_loop ADDQ #1,D6 next factor MULU D6,D5 running factorial MOVE.L D5,D0 BSR number_printer print number CMP #8,D6 all done? BNE main_loop no BRA done yes * * In this code several instructions can be replace by more efficient ones * but this has not been done since they have yet to be covered in the text. * * This code should be run from a low resolution Desktop! * * Routine to print an unsigned word in decimal. * Entered with A5 pointing an even screen address at which the printing is * to start and with D0.L containing the number to be printed. * D0-D2/D4/A0/A1 smashed. number_printer MOVEA.L A5,A0 screen column ptr MOVEQ #0,D2 leading zero flag * determine number of 'ten thousands': DIVU #10000,D0 BEQ.S no_ten_thousands MOVEQ #1,D2 no more leading zeros BSR digit_printer ADDQ.L #1,A0 next screen column MOVE #0,D0 prepare for divide * determine number of 'thousands': no_ten_thousands SWAP D0 look at remainder DIVU #1000,D0 BNE.S some_thousands CMP #0,D2 BEQ.S no_thousands some_thousands MOVEQ #1,D2 no more leading zeros BSR digit_printer ADDQ.L #1,A0 next screen column MOVE #0,D0 prepare for divide * determine number of 'hundreds': no_thousands SWAP D0 look at remainder DIVU #100,D0 BNE.S some_hundreds CMP #0,D2 BEQ.S no_hundreds some_hundreds MOVEQ #1,D2 no more leading zeros BSR digit_printer ADDQ.L #1,A0 next screen column MOVE #0,D0 prepare for divide * determine number of 'tens': no_hundreds SWAP D0 look at remainder DIVU #10,D0 BNE.S some_tens CMP #0,D2 BEQ.S no_tens some_tens BSR digit_printer ADDQ.L #1,A0 next screen column MOVE #0,D0 prepare for divide * the remainder is equal to the number of 'units': no_tens SWAP D0 always print units * (fall through to next routine) * * Routine to print a single digit. * Entered with A0 pointing to screen address of top row of first character * and with D0.W containing the digit to be printed. * D1/D4/A1 smashed. digit_printer MOVE D0,D1 MULU #8,D1 digit index -> offset * Point to correct bit image data: LEA digit_images(PC,D1),A1 MOVEQ #8-1,D4 8 rows text_loop MOVE.B (A1)+,(A0) write row of image LEA 40(A0),A0 next screen row DBRA D4,text_loop LEA -40*8(A0),A0 restore screen ptr RTS * Font data: digit_images DC.B $7C,$C6,$C6,$00,$C6,$C6,$7C,$00 "O" DC.B $18,$18,$18,$00,$18,$18,$18,$00 "1" DC.B $7C,$06,$06,$7C,$C0,$C0,$7C,$00 "2" DC.B $7C,$06,$06,$7C,$06,$06,$7C,$00 "3" DC.B $C6,$C6,$C6,$7C,$06,$06,$06,$00 "4" DC.B $7C,$C0,$C0,$7C,$06,$06,$7C,$00 "5" DC.B $7C,$C0,$C0,$7C,$C6,$C6,$7C,$00 "6" DC.B $7C,$06,$06,$00,$06,$06,$06,$00 "7" DC.B $7C,$C6,$C6,$7C,$C6,$C6,$7C,$00 "8" DC.B $7C,$C6,$C6,$7C,$06,$06,$7C,$00 "9" * (End of your code.) done * Look for "Return": LEA Variables(PC),A5 wait BSR Get_Key BEQ.S wait no key CMP.B #13,D2 Return? BNE.S wait no * Termonate: BRA END * * Initialize: START LEA Variables(PC),A5 * Open Intuition library: LEA Intuition_Name(PC),A1 MOVEQ #0,D0 open the MOVEA.L 4.W,A6 exec library JSR -408(A6) now MOVE.L D0,(A5) store base address * Allocate screen memory: MOVE.L #32000,D0 this many bytes MOVE.L #$10002,D1 clear chip memory JSR -198(A6) AllocMem MOVE.L D0,4(A5) screen ptr BEQ insufficient_memory * Set up 320*20 pixels, 4 plane display: LEA Graphics_Name(PC),A1 MOVEQ #0,D0 JSR -408(A6) MOVE.L D0,8(A5) graphics library * MOVEA.L D0,A6 LEA Bit_Map(PC),A0 MOVEQ #4,D0 bit plane depth MOVE.L #320,D1 width MOVE.L #200,D2 height JSR -390(A6) Init Bit Map * Open screen: MOVEA.L 4(A5),A0 screen ptr LEA Bit_Map+8(PC),A1 MOVE.L A0,(A1)+ plane 1 ptr LEA 8000(A0),A0 MOVE.L A0,(A1)+ plane 2 ptr LEA 8000(A0),A0 MOVE.L A0,(A1)+ plane 3 ptr LEA 8000(A0),A0 MOVE.L A0,(A1) plane 4 ptr * LEA Demo_Screen(PC),A0 MOVEA.L (A5),A6 intuition library JSR -198(A6) OpenScreen MOVE.L D0,12(A5) * tell window about screen: LEA Where(PC),A0 MOVE.L D0,(A0) * Open window: LEA Demo_Window(PC),A0 JSR -204(A6) OpenWindow MOVE.L D0,16(A5) my display * Screen to front: MOVEA.L 12(A5),A0 JSR -252(A6) ScreenToFront * Get screen base ptr: MOVEA.L 4(A5),A5 RTS * * Terminate: END MOVEA.L (A5),A6 intuition library * Close window: MOVEA.L 16(A5),A0 JSR -72(A6) CloseWindow * Close screen: MOVEA.L 12(A5),A0 screen ptr MOVEA.L (A5),A6 intuition library JSR -66(A6) CloseScreen * Deallocate (screen) memory: MOVEA.L 4.W,A6 exec library MOVEA.L 4(A5),A1 base ptr MOVE.L #32000,D0 byte size JSR -210(A6) FreeMem * insufficient_memory MOVEQ #0,D0 RTS * * Routine to get a key. Returns Z set if no key found * else key code in D2. Get_Key MOVEA.L 4.W,A6 exec MOVEA.L 16(A5),A2 window structure MOVEA.L 86(A2),A0 ptr to user port JSR -372(A6) GetMsg TST.L D0 anything there? BEQ.S key_done no MOVEA.L D0,A1 MOVE.L 14+6(A1),D1 message type MOVE 14+6+4(A1),D2 specifier (char code etc) MOVE.L D1,D3 JSR -378(A6) ReplyMsg CMP.L #$40000,D3 BEQ.S Get_Key CMP.L #$80000,D3 BEQ.S Get_Key key_done RTS * * Intuition_Name DC.B "intuition.library",0 EVEN Graphics_Name DC.B "graphics.library",0 EVEN * Demo_Screen DC.W 0 DC.W 0 DC.W 320 DC.W 200 DC.W 4 DC.B 0 DC.B 3 DC.W 0 DC.W $4F CUSTBITMAP/CUSTOMSCREEN DC.L 0 DC.L 0 DC.L 0 DC.L Bit_Map Bit_Map DS.W 1 DS.W 1 DS.B 1 DS.B 1 DS.W 1 DS.L 8 * Demo_Window DC.W 0 DC.W 12 DC.W 320 DC.W 188 DC.B 0 DC.B 0 DC.L $2C0000 request for vanilla keys/active DC.L $11D00 trap rmb DC.L 0 DC.L 0 DC.L 0 Where DC.L 0 DC.L 0 DC.W 0 DC.W 0 DC.W 0 DC.W 0 DC.W $F CUSTOMSCREEN * * offset Variables DS.L 1 intuition library ptr 0 DS.L 1 screen ptr 4 DS.L 1 graphics ligrary ptr 8 DS.L 1 my screen 12 DS.L 1 my display 16