% % ZUSIE FLIPDISC FUN % By Fredrik Andersson % % See comments at the bottom regarding different interesting logic functions you can use. % Also load 1111 into X, or it won't work! % % Variables have the following uses % A temporary scratch register % B keeps track of direction. Most significant bit is horizontal % and least significant is vertical. % C the current bit pattern to write to the current column % X MUST contain 1111 to address the flipdisc display % Y keeps track of the current column % Set starting column. Whatever will do. ldl->a h03 mova->y % Set starting row. Whatever will do. ldl->c b00100000 % Keep track of direction in b ldl->b h0 %----------------------------------------------- % Main loop %----------------------------------------------- :again %----------------------------------------------- % Horizontal update %----------------------------------------------- % If b has the top bit set, then we decrement the horizontal % position, otherwise we increment it ldc<-b sbrs decrementxy incxy sbr xydone :decrementxy decxy :xydone % Now for a little special complication: Memory position 8 % does not map to a flipdisc row. Detect this and do yet another round above. pushc movy->c ldl->a b11111000 % 8 in complementary form addac pop->c sbrz again %----------------------------------------------- % Vertical update %----------------------------------------------- % If b is non-zero (apart from the top bit), % we go up, otherwise down ldl->a b01111111 andab sbrnz goup % go down src->a mova->c sbr cdone % go up :goup addcc->a mova->c :cdone %----------------------------------------------- % Check for changed vertical % direction from wall hit %----------------------------------------------- % If c has the highest bit set, we need to go down in next round ldc<-c sbrs change_to_down % If c has the lowest bit set, we need to go up in next round src sbrs change_to_up sbr done_up_down :change_to_up incb->a mova->b sbr done_up_down :change_to_down decb->a mova->b :done_up_down %----------------------------------------------- % Check for changed horizontal % direction from wall hit %----------------------------------------------- % If y has the first bit set, we are at the leftmost % column and must switch to right-going increments % If y equals 15, we need to switch to left-going decrements pushc ldl->a b11110001 % This is 15 in complement form movy->c addac pop->c sbrz move_left % If y equals 1, we need to switch to right-going increments movy->a deca sbrz move_right sbr done :move_left pushc ldl->c b10000000 orbc->a mova->b pop->c sbr done :move_right pushc ldl->c b01111111 andbc->a mova->b pop->c %----------------------------------------------- % Write out the result to memory, % i.e. the flipdisc %----------------------------------------------- % Note, you can try different operations here % instead of XOR. Try OR for instance! :done rdxy->a xorac->mxy sbr again